An orchard has n bins, bin i holding a[i] ripe fruits. A single picker works an H-hour shift. Within any one hour the picker stays at exactly one bin and removes up to rate fruits from it (choosing the same whole-number rate for the entire shift). If a bin holds fewer than rate fruits when the picker arrives that hour, the picker still spends the whole hour there and simply empties it; leftover picking capacity in that hour is not carried to another bin.
So a bin of a[i] fruits takes ceil(a[i] / rate) hours to clear. Find the smallest whole-number rate (at least 1) that clears all bins within H hours in total.
Line 1: two integers n and H.
Line 2: n space-separated integers, the fruit counts per bin.
A single integer: the smallest picking rate that finishes within H hours.
Example 1
Input
4 8 3 6 7 11
Expected
4
Explanation
At rate 4 the bins take ceil(3/4)+ceil(6/4)+ceil(7/4)+ceil(11/4) = 1+2+2+3 = 8 hours, exactly the shift; rate 3 would need 1+2+3+4 = 10 hours, which overruns.
Example 2
Input
3 3 1 1 1
Expected
1
Explanation
Three bins and a 3-hour shift means one hour per bin, so any rate of 1 or more works and the smallest is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →