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. visual studio各个版本的差异

  2. 常用sql,在做项目时用mysqlWorkBeach里面自动生成的

    -- 修改表中的字段的长度ALTER TABLE `sfkbbs`.`sfk_father_module` CHANGE ) NULL DEFAULT NULL COMMENT '父板块名字' ; 在 ...

  3. 【bzoj1502】 NOI2005—月下柠檬树

    http://www.lydsy.com/JudgeOnline/problem.php?id=1502 (题目链接) 今天考试题,从来没写过圆的面积之类的东西..GG 题意 一颗树由n个圆台组成,现 ...

  4. java 中LinkedList的学习

    Java中,所有链表实际上都是双向链表的,即每个结点还存放在着指向前驱结点的引用. LinkedList中的contains方法检测某个元素是否出现在链表中. LinkedList类提供了一个用来访问 ...

  5. MyEclipse------从服务器下载文件

    Downfile.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

  6. 打印多边形的菱形(for的嵌套)

    Console.WriteLine("请输入一个数字,会出现一个多边的菱形:"); int n = Convert.ToInt32(Console.ReadLine()); ; i ...

  7. VirtualBox安装Fedora20

    工具/原料 Fedora20 32位版(必须是32位,VirtualBox不识别64位操作系统) Oracle VM VirtualBox 方法/步骤 1 搜索Oracle VM VirtualBox ...

  8. hdu 1013 Digital Roots

    #include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...

  9. 使用guava带来的方便

    ​    ​guava是在原先google-collection 的基础上发展过来的,是一个比较优秀的外部开源包,最近项目中使用的比较多,列举一些点.刚刚接触就被guava吸引了... ​    ​这 ...

  10. _AR="ar" _ARFLAGS="-ruv"

    _AR="ar" _ARFLAGS="-ruv" 详情看GCC详解, 表3.14 Makefile中常见预定义变量 命 令 格 式 含义 AR 库文件维护程序的 ...