cswork / OA打开练习工作台

JPMorgan ChaseOA #7

Count Dropped Requests

估计简单可在线判题

考点(AI 标注)模拟/实现

A positive event adds that many threads, and −1 represents a request. A request consumes and destroys one thread, and it is dropped if no thread is available; find the total number dropped. This is not sliding-window rate limiting.

输入格式

The first line contains n, followed by the event array; 1≤n≤100000, and each element is −1 or 1..10000.

输出格式

Output a single integer answer.

样例 1

输入:

4
1 -1 -1 1

输出:

1

样例 2

输入:

2
-1 -1

输出:

2

样例 3

输入:

4
3 -1 -1 -1

输出:

0

样例说明

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