All problems

Problem 105

Koko Eating Bananas

Medium · 20 pts · Array, Binary Search

Problem

Koko has N piles of bananas and H hours. She picks one eating speed S (bananas per hour). Each hour she chooses a pile and eats S bananas from it; if the pile has fewer than S bananas, she eats the whole pile and does not move to another pile during that hour. Find the smallest integer speed S that lets her finish every pile within H hours. At speed S, a pile of size p takes ceil(p / S) hours. A higher speed never takes longer, so binary search on S between 1 and the largest pile, checking the total hours for each candidate.

Input

First line: integers N and H. Second line: N pile sizes.

Output

Print the minimum eating speed.

Constraints

1 <= N <= 10000; N <= H <= 1000000000; 1 <= pile <= 1000000000

Example input

4 8
3 6 7 11

Example output

4

Explanation

With piles 3 6 7 11 and speed 4, the piles take 1, 2, 2 and 3 hours, which is 8 hours, exactly H. At speed 3 they would take 1 + 2 + 3 + 4 = 10 hours, too many, so the answer is 4.

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

Previous: Median of Two Sorted Arrays Next: Capacity To Ship Packages