cswork / OA打开练习工作台

AmazonOA #88

Min Operations Delivery Truck (Single Truck Capacity Halving)

估计中等可在线判题

考点(AI 标注)贪心调度原地数组

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.

输入格式

The first line contains n T (1≤n≤100000, 1≤T≤10⁹), and the second line contains n weights (1..10⁹).

输出格式

Output a single integer answer.

样例 1

输入:

4 8
8 4 2 1

输出:

4

样例 2

输入:

3 8
9 8 1

输出:

2

样例 3

输入:

2 1
2 2

输出:

0

样例说明

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.