← 返回 optiver 的题目列表Minimum Eating Speed to Finish Bananas
类型:online_judge
You are given an integer array piles where piles[i] is the number of bananas in the i-th pile. The guards will return in h hours.
Koko chooses an integer eating speed k (bananas per hour). Each hour, she can pick one pile and eat:
exactly k bananas if the pile has at least k bananas remaining, or
the whole pile if it has fewer than k bananas; in that case she does not eat from any other pile during that hour.
Return the minimum integer k such that she can finish all bananas within h hours.
Input (stdin)
Line 1: array piles (e.g., [3,6,7,11])
Line 2: integer h
Output (stdout)
One integer: the minimum feasible k
Constraints
1 <= len(piles) <= 10^4
1 <= piles[i] <= 10^9
len(piles) <= h <= 10^9
Example
Input: piles = [3,6,7,11], h = 8
Output: 4
Example
Input
[3,6,7,11]
8
Output
4