codeforces Police Recruits
2015-12-18 21:44
393 查看
Description
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 Input
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
Hint
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.
水题~~
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 Input
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
Hint
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.
水题~~
[code]#include <iostream> using namespace std; int main() { int n; cin>>n; int s=0,num=0; for(int i=0; i<n; i++) { int a; cin>>a; if(a>0) s+=a; else { if(s>0) { s--; } else num++; } } cout<<num<<endl; return 0; }
相关文章推荐
- 快速理解RequireJs中的config
- hdu2152 Fruit (背包dp)
- NSValue用法
- Farey Sequence(Poj2478)(快速求欧拉函数)
- GPUImageMovie播放控制
- datagrid分页
- 38 用break和continue改变流程 课后
- 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
- 17-1 UI高级可视化设计
- 15 UITabBarController、block高级(+UIMenuController_UIPasteBoard、MBProgressHud)
- 14-1 UITableView综合-模态viewController、单例(LED,Neon)
- 组件_ UIToolbar 与 组件_UISearchBar
- UITableView的使用
- 13 自定义cell、cell自适应高度、 多种类型的cell混合使用、 UITableViewController、model类
- <LeetCode OJ> 303. Range Sum Query - Immutable
- 12 UITableView编辑和移动 、UITableViewController、(+UIDatePicker)
- 11 UITableView表视图
- UIPickerView
- UIStoryboard和UIResponder
- UIImageView和UIImage