problems / 244

Draining the Upload Backlog

medium binary-search arrays 1000 ms · 256 MB

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.

Example 1

Input

4 8
3 6 7 11

Output

4

Example 2

Input

4 4
9 2 15 4

Output

15

Example 3

Input

3 3000000000
1000000000 1000000000 1000000000

Output

1

Hints · reveal one at a time if you're stuck

Hint 1

If someone hands you a rate k, how quickly can you check whether it clears the backlog in time? And if k works, does k + 1 work too?

Hint 2

The answer lies between 1 and the largest file size, and "fast enough" only switches from no to yes once as k grows. Binary search on k, using the check from the first hint. Count the hours in a 64-bit integer.

report an issue Prefer your own editor? sooks prep 244 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.