Codeforces--427a--police recruits

Source: Internet
Author: User
Tags time limit
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;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.