cswork / OAOpen practice workspace

JPMorgan ChaseOA #7

Count Dropped Requests

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

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.

Input

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

Output

Output a single integer answer.

Example 1

Input:

4
1 -1 -1 1

Output:

1

Example 2

Input:

2
-1 -1

Output:

2

Example 3

Input:

4
3 -1 -1 -1

Output:

0

Example notes

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

Editorial

Loading solution…