All problems

Problem 872

Minimum Limit of Balls in a Bag

Medium · 20 pts · Array, Binary Search

Problem

Bag i holds NUMS[i] balls. In one operation you split any bag into two bags with a positive number of balls each. After at most MAXOPS operations, the penalty is the largest number of balls in any bag. Minimise the penalty. To make every bag hold at most P balls, a bag of n balls needs ceil(n / P) - 1 splits, so binary search on P and check whether the total number of splits is within MAXOPS.

Input

The first line contains N and MAXOPS. The second line contains the N bag sizes.

Output

Print the minimum possible penalty.

Constraints

1 <= N <= 100000; 1 <= MAXOPS, NUMS[i] <= 10^9

Example input

1 2
9

Example output

3

Explanation

With one bag of 9 balls and 2 operations, split it into 6 and 3, then 6 into 3 and 3, leaving 3 3 3. The penalty is 3, and 2 balls per bag would need 4 splits.

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

Previous: Maximum Value at a Given Index in a Bounded Array Next: Minimized Maximum of Products Distributed to Any Store