Pipelined
Time limit1sMemory limit1024 MB
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 cars using a single work slot. Producing the -th car requires production stages. The work slot is the interval on the number line. While the -th car is in production, it occupies a half-open interval of length 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 -th process occupies , after the move it occupies . A process does not move if the move would overlap the interval of another process. A process that moves out of 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 -th process places it on . 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 , the number of cars to produce. ()
The second line contains the stage counts of the cars, separated by spaces. ()
Output
Print the minimum number of seconds until all cars have finished passing through the work slot.
Hint
A half-open interval contains every number greater than or equal to and less than .