Problems > Minimum Eating Speed

Minimum Eating Speed

Difficulty: 1600 3500 ms 128 MB

binary-search

There are N banana piles; eating at speed k clears ⌈p/k⌉ hours per pile (one pile per hour session). Find the minimum integer speed to finish all piles within H hours.

Input: the first line has N and H (H ≥ N); the second line has the N pile sizes.

Output: the minimum speed k.

Constraints:

  • 1 ≤ N ≤ 105
  • N ≤ H ≤ 4×105
  • 1 ≤ pi ≤ 109

Sample Tests

Input 1
4 8
3 6 7 11
Output 1
4
Input 2
1 1
1000000000
Output 2
1000000000

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.