Draining the Upload Backlog
A backup agent has n files waiting in its upload queue; file i is s_i MB. The agent works in whole hours and is configured with an integer rate limit of k MB per hour.
Each hour the agent picks one unfinished file and uploads at most k MB of it. If less than k MB of that file was left, the file is done and the rest of the hour stays idle: an hour is never shared between two files. So file i takes exactly ⌈s_i / k⌉ hours, and the whole backlog takes the sum of these over all files.
The backup window is H hours long. Find the smallest integer rate k (in MB per hour) that clears the whole backlog within H hours.
Input
The first line contains two integers n and H (1 ≤ n ≤ 2·10^5, n ≤ H ≤ 10^14): the number of files and the length of the backup window in hours.
The second line contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 10^9): the file sizes in MB.
Output
Print one integer: the smallest positive integer k such that the sum of ⌈s_i / k⌉ over all files is at most H. Since H ≥ n, such a k always exists.
Notes
In the first example, at k = 4 the files take 1 + 2 + 2 + 3 = 8 hours, which fits. At k = 3 they take 1 + 2 + 3 + 4 = 10 hours, which is too many.
In the second example there are only as many hours as files, so every file must finish in a single hour and k must be at least the largest size, 15.
In the third example the agent can go as slowly as 1 MB per hour. The total number of hours can be as large as 2·10^14, so use 64-bit integers to add up the hours.