← 返回 apple 的题目列表Koko Eating Bananas
类型:qbank
Koko loves to eat bananas. There are n piles of bananas, the i\-th pile has piles[i] bananas. The guards have gone and will come back in h hours.
Examples
Example 1:
Input: piles = [3,6,7,11], h = 8
Output: 4
Explanation:
With k=4, hours needed = ceil(3/4) + ceil(6/4) + ceil(7/4) + ceil(11/4) = 1+2+2+3 = 8.
Example 2:
Input: piles = [30,11,23,4,20], h = 5
Output: 30
Explanation:
Only 5 hours available and 5 piles, so Koko must finish each pile in a single hour; k = max pile = 30.
Example 3:
Input: piles = [30,11,23,4,20], h = 6
Output: 23
Explanation:
With k=23, hours = ceil(30/23)+ceil(11/23)+ceil(23/23)+ceil(4/23)+ceil(20/23) = 2+1+1+1+1 = 6.
Constraints
1 <= piles.length <= 10^4
piles.length <= h <= 10^9
1 <= piles[i] <= 10^9