AirbnbOA #4
Minimum Eating Speed
Estimated MediumJudge-ready
Topics (AI-labelled)Binary Search
In each unit of time you can eat from only one box/pile, at most d items; eating fewer than d still uses a full unit of time, and leftover capacity cannot carry over to the next box/pile. Find the minimum positive integer speed that finishes everything within the deadline.
Input
The first line contains n, the second line contains n quantities, and the third line contains the deadline h. The original numeric upper bounds are missing; this site adds 1≤n≤200000, quantities in 1..10^9, and h≤10^18. On this site 1≤h; the original does not guarantee feasibility, so this site outputs −1 when it is infeasible.
Output
Output a single integer answer.
Example 1
Input:
4
4 9 11 17
8
Output:
6
Example 2
Input:
4
3 6 7 11
8
Output:
4
Example 3
Input:
2
2 2
1
Output:
-1
Example notes
The outputs of the three public examples are, in order: 6; 4; -1. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…