Balloon Factory
InterviewTime limit1sMemory limit256 MB
Find the minimum time for N workers, each producing one balloon every A_i minutes, to finish M balloons in parallel.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy, Math, Array
- Solved
- No attempts yet
Problem
There are staff members who share the work of making balloons. Staff member takes minutes to make one balloon and can start the next balloon immediately after finishing one. All staff members start working together at minute . Find the minimum number of minutes needed until all balloons are finished. Balloon designs do not matter.
For example, a staff member who takes minutes per balloon and starts at minute finishes the first balloon at minute and the second balloon at minute .
Input
The first line contains the number of staff members and the number of balloons ().
The second line contains integers, the time in minutes each staff member takes to make one balloon ().
Output
Print a single integer, the minimum number of minutes needed to finish all balloons.
Hint
Whether a candidate time of minutes is enough can be counted directly. Staff member finishes balloons within minutes, so balloons can be finished within minutes when the total over all staff members is at least . Binary-searching the range of possible times with this check gives the minimum time.