Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

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:

  1. Firstly one person is hired.
  2. Then crime appears, the last hired person will investigate this crime.
  3. One more person is hired.
  4. One more crime appears, the last hired person will investigate this crime.
  5. Crime appears. There is no free policeman at the time, so this crime will go untreated.
  6. One more person is hired.
  7. One more person is hired.
  8. One more person is hired.

The answer is one, as one crime (on step 5) will go untreated.

Source

题意:n个数,-1代表一个罪犯,正数代表有多少警察,每个警察可以调查一个罪犯,罪犯和警察按照顺序依次出现,
   如果罪犯出现时警察的个数为0,未被调查的罪犯数+1,输出未被调查的罪犯数。
题解:代码中a代表警察,b代表罪犯,ans代表未被调查的罪犯。
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
int i,n,ans,a,b,data;
scanf("%d",&n);
a=,b=,ans=;
for(i=;i<n;i++)
{
scanf("%d",&data);
if(data>)
{
a+=data;
}
if(data<)
{
b-=data;
if(b>a)
{
ans++;
b--;
}
}
}
printf("%d\n",ans);
return ;
}

CodeForces - 427A (警察和罪犯 思维题)的更多相关文章

  1. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  3. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

  4. Codeforces 1365G - Secure Password(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 首先考虑一个询问 \(20\) 次的方案,考虑每一位,一遍询问求出下标的这一位上为 \(0\) 的位置上值的 bitwise or,再一遍 ...

  5. Codeforces 1129E - Legendary Tree(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\}, ...

  6. codeforces 848B Rooter's Song 思维题

    http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...

  7. Codeforces 729D Sea Battle(简单思维题)

    http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html   原 题意:海战 ...

  8. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces 901C. Bipartite Segments(思维题)

    擦..没看见简单环..已经想的七七八八了,就差一步 显然我们只要知道一个点最远可以向后扩展到第几个点是二分图,我们就可以很容易地回答每一个询问了,但是怎么求出这个呢. 没有偶数简单环,相当于只有奇数简 ...

随机推荐

  1. 洛谷P2014 TYVJ1051 选课

    题目描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课,每门课有个学分,每门课有一 ...

  2. HackerRank Extra long factorials

    传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...

  3. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  4. AndroidManifest File Features

    http://www.android-doc.com/guide/topics/manifest/manifest-intro.html The following sections describe ...

  5. jquery设置和获得checkbox选中问题

    1.设置checkbox选中: //选中多选框 checkbox=$("#agentinfo input[name='veri[]']"); //循环多选框中的值 checkbox ...

  6. MyEclipse中防止代码格式化时出现换行的情况的设置

    编辑完成代码,用MyEclipse的代码格式化后,本来不长的代码也被自动转成了多行.虽然自动换行以后在编辑器中一眼就能看到全部的代码,但是可读性却大打折扣,避免出现这种情况的办法是: 1.Java代码 ...

  7. Java-TCP Socket编程

    TCP 的 Java 支持 协议相当于相互通信的程序间达成的一种约定,它规定了分组报文的结构.交换方式.包含的意义以及怎样对报文所包含的信息进行解析,TCP/IP 协议族有 IP 协议.TCP 协议和 ...

  8. Jquery 扩展获取RUL参数

    //扩展获取url $.extend({ getUrlVars: function () { var vars = [], hash; var hashes = window.location.hre ...

  9. Json数据

    <title>无标题文档</title>//使用 jquery 必须的先加载 <script src="jquery-2.1.1.min.js"> ...

  10. LUA之string的使用

    --string.len(s)          --返回字符串s的长度 --string.rep(s, n)--返回重复n次字符串s的串,你使用string.rep("a", 2 ...