A worker must clear n batches of jobs, where batch i contains piles[i] jobs. The worker picks a single integer processing rate s (jobs per hour) and keeps it fixed. During each hour the worker focuses on exactly one batch: they process up to s jobs from it. If a batch has fewer than s jobs remaining, the worker finishes that batch during the hour and does not carry the leftover capacity to another batch that hour. Thus a batch of size p takes ceil(p / s) hours.
Given a deadline of H hours (with H >= n, so a solution always exists), return the smallest integer rate s >= 1 for which the total number of hours needed is at most H.
Line 1: an integer n, the number of batches.
Line 2: n space-separated positive integers, the batch sizes.
Line 3: an integer H, the hour budget.
A single integer: the minimum feasible processing rate s.
Example 1
Input
4 3 6 7 11 8
Expected
4
Explanation
At rate 4 the batches take 1+2+2+3 = 8 hours, which meets the deadline; rate 3 would need 1+2+3+4 = 10 hours, so 4 is the minimum.
Example 2
Input
5 30 11 23 4 20 6
Expected
23
Explanation
With only 6 hours for 5 batches there is almost no slack; rate 23 clears every batch in at most two hours for a total of 6, and no smaller rate fits.
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 →