A. Police recruits time limit/test 1 second memory limit per test 256 megabytes input standard input output standard o Utput
The police Department of your city has just started its journey. Initially, they don ' t have any manpower. So, they started hiring the new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate a only one crime during his/her.
If There is no police officer free (isn ' t busy with crime) during the occurrence of a crime, it'll go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which would go to untreated. Input
The "a" of input would contain an integer n (1≤n≤105), the number of events. The next line would contain n space-separated integers.
If the integer is-1 then it means a crime has occurred. Otherwise, the integer would be positive, the number of officers recruited together at this time. No more than officers'll be recruited in a time. Output
Print A single integer, the number of crimes which would go untreated. Examples Input
3
-1-1 1
Output
2
Input
8
1-1 1-1-1 1 1 1
Output
1
Input
One
-1-1 2-1-1-1-1-1-1-1-1
Output
8
Note
Lets consider the second example:firstly one person is hired. Then crime appears, the last hired person would investigate this crime. One more is hired. One more crime appears, the last hired person would investigate this crime. Crime appears. There is no-policeman at the time and so this crime'll go untreated. One more is hired. One more is hired. One more is hired.
The answer is one and as one crime (on step 5) 'll go untreated.
Negative numbers are criminal occurrences, positive numbers are the number of new policemen, a policeman handling a crime, and no handling of the crimes before the police. Output there are several crimes not dealt with
Water ~
#include <iostream>
#include <deque>
#include <cstring>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <cstring>
#include <functional>
#include <queue >
#define MIN-1E9
using namespace std;
int main ()
{
int n;
while (Cin>>n)
{
int police=0,ans=0;
while (n--)
{
int temp;
cin>>temp;
if (temp<0)
if (police)
police--;
else
ans+=1;
else
police+=temp;
}
cout<<ans<<endl;
}
return 0;
}