cswork / OA打开练习工作台

GithubOA #1

Bridge Car Weight Problem

估计中等可在线判题

考点(AI 标注)贪心调度

Vehicles cross the bridge in their original queue order, with at most two vehicles on the bridge at once. When the front vehicle leaves, the third vehicle enters immediately, and so on. You may remove any vehicles; find the minimum number of removals so that the bridge is never overloaded. You cannot insert waiting time or reorder the vehicles.

输入格式

The first line contains n U, and the second line contains n vehicle weights. The original has no numeric bounds; this site adds 1≤n≤200000 and 1≤U,weight[i]≤10^9. A vehicle that is overweight on its own must also be removed.

输出格式

Output one integer, the answer.

样例 1

输入:

8 9
5 3 8 1 8 7 7 6

输出:

4

样例 2

输入:

3 6
3 3 3

输出:

0

样例 3

输入:

1 9
10

输出:

1

样例说明

The outputs of the three public examples are, in order: 4; 0; 1. They have been checked by independent enumeration or direct simulation.