cswork / OA打开练习工作台

AmazonOA #220

Get Minimum Number Of Bulbs Off

估计中等可在线判题

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

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.

输入格式

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 a single integer, the answer.

样例 1

输入:

5
2 1 3 4 3

输出:

2

样例 2

输入:

3
0 0 0

输出:

0

样例 3

输入:

4
1 1 2 4

输出:

0

样例说明

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.