AmazonOA #228
Get Minimum Dock Bays
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchStacks & Heaps
Trucks must start unloading in input order, and a free dock immediately takes the next truck; trucks that start at the same time are assigned in input order. All trucks must finish within time T; find the minimum number of docks. Trucks cannot be reordered.
Input
The first line contains n T; the second line contains each truck's duration. 1≤n≤50000, 1≤T≤10^15, 1≤duration≤min(T,10^9). The source has a note about reading the upper bound of T; this site explicitly uses 10^15.
Output
Output a single integer, the answer.
Example 1
Input:
5 8
3 4 3 2 3
Output:
3
Example 2
Input:
3 7
2 3 1
Output:
1
Example 3
Input:
2 2
2 2
Output:
2
Example notes
The answers are 3, 1 and 2. In the first example two docks would need 9 minutes, which does not meet the limit of 8.
Editorial
Loading solution…