cswork / OAOpen practice workspace

GeicoOA #1

Bridge Weight Limit — Minimum Drivers Turn Back

Estimated MediumJudge-ready

Topics (AI-labelled)Greedy

Keep a subsequence of the original queue such that, for every pair of adjacent vehicles in the kept sequence, the sum of their weights does not exceed the bridge limit U. Output the minimum number of drivers who must leave. A vehicle whose own weight exceeds U must also leave.

Input

The input contains U, N, and N vehicle weights. 1≤N≤100000, 1≤weight[i],U≤10^9.

Output

Output the minimum number of drivers who must leave.

Example 1

Input:

9
8
5 3 8 1 8 7 7 6

Output:

4

Example 2

Input:

7
8
7 6 5 2 7 4 5 4

Output:

5

Example 3

Input:

7
4
3 4 3 1

Output:

0

Editorial

Loading solution…