Codeforces Round #244 (Div. 2)a Police Recruits
2014-05-03 01:43
435 查看
A. Police Recruits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input
The first line of input will contain an integer n (1 ≤ n ≤ 105),
the number of events. The next line will contain n space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output
Print a single integer, the number of crimes which will go untreated.
Sample test(s)
input
output
input
output
input
output
Note
Lets consider the second example:
Firstly one person is hired.
Then crime appears, the last hired person will investigate this crime.
One more person is hired.
One more crime appears, the last hired person will investigate this crime.
Crime appears. There is no free policeman at the time, so this crime will go untreated.
One more person is hired.
One more person is hired.
One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
首先给出n个整数,正数表示新增多少个警察,-1表示要派出一个警察,当为-1且没有警察可派时,结果加1;
思路:模拟即可
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input
The first line of input will contain an integer n (1 ≤ n ≤ 105),
the number of events. The next line will contain n space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output
Print a single integer, the number of crimes which will go untreated.
Sample test(s)
input
3 -1 -1 1
output
2
input
8 1 -1 1 -1 -1 1 1 1
output
1
input
11-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 will investigate this crime.
One more person is hired.
One more crime appears, the last hired person will investigate this crime.
Crime appears. There is no free policeman at the time, so this crime will go untreated.
One more person is hired.
One more person is hired.
One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
首先给出n个整数,正数表示新增多少个警察,-1表示要派出一个警察,当为-1且没有警察可派时,结果加1;
思路:模拟即可
#include<cstdio> int main() { int n,ans,i,d,s; while(scanf("%d",&n)!=EOF) { s=0; ans=0; for(i=1;i<=n;i++) { scanf("%d",&d); if(d>0) s+=d; else { if(s+d<0) ans+=1; else s=s+d; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- Codeforces Round #244 (Div. 2) E. Police Patrol(数学)
- Codeforces Round #244 (Div. 2) E. Police Patrol
- Codeforces Round #244 (Div. 2)D (后缀自己主动机)
- Codeforces Round #244 (Div. 2)
- Codeforces Round #244 (Div. 2) A~C
- Codeforces Round #244 (Div. 2) B. Prison Transfer
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #275 (Div. 2) --B Friends and Presents
- Codeforces Round #297 (Div. 2)
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- Codeforces Round #274 (Div. 2) d Long Jumps 尺取法 + set
- Codeforces Round #247 (Div. 2) D Random Task
- Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn(LCA思想)
- Codeforces Round #426 (Div. 2)The Meaningless Game【数学题】【水题】
- Codeforces Round #131 (Div. 2) 完整题解
- Codeforces Round #427 (Div. 2) - A - Key races
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
- Codeforces Round #214 (Div. 2)
- Codeforces Round #191 (Div. 2)---A. Flipping Game
- Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shift