cswork / OAOpen practice workspace

AmazonOA #220

Get Minimum Number Of Bulbs Off

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

All bulbs start on and are checked from left to right: if the total brightness of the earlier bulbs that are still on is strictly greater than the current bulb's brightness, the current bulb turns off. You may arrange the bulbs in any order; find the minimum number turned off. Even if the rule is read as using the initial brightness of all earlier bulbs, the optimal answer is the same: just put all discarded bulbs at the end.

Input

The first line contains n; the second line contains the brightness values. The original text had no numeric bounds; this site uses 1≤n≤200000, 0≤brightness≤10^9.

Output

Output a single integer, the answer.

Example 1

Input:

5
2 1 3 4 3

Output:

2

Example 2

Input:

3
0 0 0

Output:

0

Example 3

Input:

4
1 1 2 4

Output:

0

Example notes

The answers are 2, 0 and 0. In the first example 1, 2 and 3 are kept for a total of 6, and the remaining 4 and 3 turn off.

Editorial

Loading solution…