cswork / OAOpen practice workspace

GithubOA #1

Bridge Car Weight Problem

Estimated MediumJudge-ready

Topics (AI-labelled)Greedy

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.

Input

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

Output one integer, the answer.

Example 1

Input:

8 9
5 3 8 1 8 7 7 6

Output:

4

Example 2

Input:

3 6
3 3 3

Output:

0

Example 3

Input:

1 9
10

Output:

1

Example notes

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

Editorial

Loading solution…