AmazonOA #88
Min Operations Delivery Truck (Single Truck Capacity Halving)
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
A single truck has initial capacity T. Each time, choose any undelivered package whose weight is ≤ the current capacity; after it is delivered, the capacity is halved and rounded down. Maximize the number of packages delivered.
Input
The first line contains n T (1≤n≤100000, 1≤T≤10⁹), and the second line contains n weights (1..10⁹).
Output
Output a single integer answer.
Example 1
Input:
4 8
8 4 2 1
Output:
4
Example 2
Input:
3 8
9 8 1
Output:
2
Example 3
Input:
2 1
2 2
Output:
0
Example notes
Example 1: 8, 4, 2, 1 in turn, delivering 4. Example 2: skip 9, deliver 8 and then 1, 2 in total. Example 3: both packages are heavier than the capacity 1, so 0 are delivered.
Editorial
Loading solution…