All problems

Problem 363

Smallest Divisor Given a Threshold

Medium · 20 pts · Array, Binary Search

Problem

Choose a positive integer divisor D, divide every element of the array by D, and round each result up to the nearest integer. Add up these rounded results. Find the smallest D for which the total is at most the given threshold T. A larger divisor never makes the total larger, so you can binary search for the smallest D that works. The threshold is always at least N, so an answer exists.

Input

First line: N and T. Second line: N positive integers.

Output

Print the smallest valid divisor.

Constraints

1 <= N <= 50000; 1 <= A[i] <= 1000000; N <= T <= 1000000

Example input

4 6
1 2 5 9

Example output

5

Explanation

For 1 2 5 9 with T = 6: dividing by 5 gives 1 + 1 + 1 + 2 = 5, which is within 6, while dividing by 4 gives 1 + 1 + 2 + 3 = 7, which is too much. So the answer is 5.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Minimum Days to Make Bouquets Next: Search a Sorted 2D Matrix