Police Recruits

简介: Police Recruits

文章目录

一、Police Recruits

总结


一、Police Recruits

本题链接:Police Recruits


题目:

A. Police Recruits

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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 ≤ 1e5), 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.


Examples

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:


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.


本博客给出本题截图:

image.png

image.png

题意:输入-1证明产生了一个犯罪,输入其他正整数(小于10)代表招募警察的数量,每个警察在处理完一个犯罪后就会退休,且初始警察数为0,问有多少起犯罪是没有警察出来的

AC代码

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int res = 0, cnt = 0;
    for (int i = 0; i < n; i ++ )
    {
        int a;
        cin >> a;
        if (a == -1) 
        {
            if (cnt == 0) res ++;
            else cnt --;
        }
        else cnt += a;
    } 
    cout << res << endl;
    return 0;
}

总结

水题,不解释


目录
相关文章
|
4天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
328 102
|
4天前
|
JSON fastjson Java
FastJson 完全学习指南(初学者从零入门)
摘要:本文是FastJson的入门学习指南,主要内容包括: JSON基础:介绍JSON格式特点、键值对规则、数组和对象格式,以及嵌套结构的访问方式。FastJson是阿里巴巴开源的高性能JSON解析库,具有速度快、功能全、使用简单等优势,并介绍如何引入依赖,如何替换Springboot默认的JackJson。 核心API: 序列化:将Java对象转换为JSON字符串,演示对象、List和Map的序列化方法; 反序列化:将JSON字符串转回Java对象,展示基本对象转换方法;
|
5天前
|
缓存 JavaScript 前端开发
JavaScript 的三种引入方法详解
在网页开发中,JavaScript 可通过内联、内部脚本和外部脚本三种方式引入 HTML 文件,各具适用场景。本文详解其用法并附完整示例代码,帮助开发者根据项目需求选择合适的方式,提升代码维护性与开发效率。
197 110
|
5天前
|
Android开发 开发者 Windows
这是我设计的一种不关机,然后改造操作系统的软件设计思路2.0版本
本文介绍了在不重启系统的情况下实现操作系统改造的两种方案。第一种方案通过SLFM Recovery模式,在独立于操作系统的最高权限环境下完成系统更新与改造,并支持断电恢复与失败回滚。第二种方案采用多分区机制,通过SLFM套件在独立分区中完成系统改造,适用于可中断与不可中断服务场景,确保系统更新过程的安全与稳定。
230 132