All problems

Problem 566

Maximum Candies Allocated to K Children

Medium · 20 pts · Array, Binary Search

Problem

There are N piles of candies, and pile i has A[i] candies. You may split any pile into smaller piles, but you cannot merge two piles together. Give each of K children one whole pile, so that every child receives the same number of candies. Some candies may be left over. Find the largest number of candies each child can get (0 if there is no way to give everyone at least one). A size x works when the sum of floor(A[i] / x) is at least K, so binary search on x. The numbers in this problem can be larger than a 32-bit int can hold (about 2.1 × 10^9), so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).

Input

The first line contains N and K. The second line contains N integers.

Output

Print the maximum number of candies per child.

Constraints

1 <= N <= 100000; 1 <= A[i] <= 10^7; 1 <= K <= 10^12

Example input

3 3
5 8 6

Example output

5

Explanation

With piles 5 8 6 and K = 3, give each child 5 candies: the pile of 5 is used whole, and the piles of 8 and 6 each give one pile of 5. Size 6 gives only 2 piles, so the answer is 5.

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

Previous: Find Right Interval Next: Minimum Time to Complete Trips