Under construction

Still being built. Things may change

Pipelined

Time limit1sMemory limit1024 MB

Summary
Find the minimum seconds for N cars, each with stage count s_i, to pass through the slot [0,1) when each car's interval moves by its own length every second.
Level

Hard8 of 10

Topics
Greedy, Math, Simulation
Solved
No attempts yet

Problem

Roha works at Hyundai Motor and wants to plan the production of NN cars using a single work slot. Producing the ii-th car requires sis_i production stages. The work slot is the interval [0,1)[0,1) on the number line. While the ii-th car is in production, it occupies a half-open interval of length 1si\frac{1}{s_i} in the slot. Starting at time 0, the following happens in order every second.

  • First, every assigned production process moves backward by its own length. If the ii-th process occupies [j−1si,jsi)[\frac{j-1}{s_i}, \frac{j}{s_i}), after the move it occupies [jsi,j+1si)[\frac{j}{s_i}, \frac{j+1}{s_i}). A process does not move if the move would overlap the interval of another process. A process that moves out of [0,1)[0,1) is complete and no longer occupies any space.
  • Roha may pick one of the unassigned production processes and assign it to the slot, or may assign none. Assigning the ii-th process places it on [0,1si)[0,\frac{1}{s_i}). It cannot be assigned if that interval overlaps an interval held by another process.

Find the minimum number of seconds until all cars have passed through the work slot.

Input

The first line contains NN, the number of cars to produce. (1≤N≤200,0001 \le N \le 200,000)

The second line contains the stage counts s1,s2,…,sNs_1, s_2, \ldots, s_N of the NN cars, separated by spaces. (1≤si≤200,0001 \le s_i \le 200,000)

Output

Print the minimum number of seconds until all cars have finished passing through the work slot.

Hint

A half-open interval [a,b)[a, b) contains every number greater than or equal to aa and less than bb.

Examples1

  1. Example 1

    Input
    4
    5 7 8 11
    
    Expected output
    14