cf978E Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If xx is the number of passengers in a bus just before the current bus stop and yy is the number of passengers in the bus just after current bus stop, the system records the number y−xy−x. So the system records show how number of passengers changed.
The test run was made for single bus and nn bus stops. Thus, the system recorded the sequence of integers a1,a2,…,ana1,a2,…,an (exactly one number for each bus stop), where aiai is the record for the bus stop ii. The bus stops are numbered from 11 to nn in chronological order.
Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to ww (that is, at any time in the bus there should be from 00 to ww passengers inclusive).
Input
The first line contains two integers nn and ww (1≤n≤1000,1≤w≤109)(1≤n≤1000,1≤w≤109) — the number of bus stops and the capacity of the bus.
The second line contains a sequence a1,a2,…,ana1,a2,…,an (−106≤ai≤106)(−106≤ai≤106), where aiai equals to the number, which has been recorded by the video system after the ii-th bus stop.
Output
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to ww. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
Examples
3 5
2 1 -3
3
2 4
-1 1
4
4 10
2 4 1 2
2
Note
In the first example initially in the bus could be 00, 11 or 22 passengers.
In the second example initially in the bus could be 11, 22, 33 or 44 passengers.
In the third example initially in the bus could be 00 or 11 passenger.
题解:
只需要从后向前找出人最多的时刻,和最少的时刻。
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
const int INF=0x3f3f3f3f;
int sum[MAXN]; int main()
{
int n,w,a;
scanf("%d%d",&n,&w);
int MAX=0,MIN=INF;
for (int i = 1; i <=n ; ++i) {
scanf("%d",&a);
sum[i]=sum[i-1]+a;
MAX=max(MAX,sum[i]);
MIN=min(MIN,sum[i]);
}
MAX=w-MAX;
MIN=MIN>0?0:-MIN;
if(MAX-MIN+1<0) printf("0\n");
else printf("%d\n",MAX-MIN+1); return 0;
}
cf978E Bus Video System的更多相关文章
- CF978E Bus Video System【数学/前缀和/思维】
[链接]: CF [分析]: 设上车前人数 x ,中途最大人数为 x+max ,最小人数为 x+min (max≥0,min≤0) 可得不等式组 x+max≤w, x+min≥0 整数解个数为 max ...
- Bus Video System CodeForces - 978E (思维)
The busses in Berland are equipped with a video surveillance system. The system records information ...
- Codeforces 978E:Bus Video System
题目链接:http://codeforces.com/problemset/problem/978/E 题意 一辆公交车,在每站会上一些人或下一些人,车的最大容量为w,问初始车上可能有的乘客的情况数. ...
- pygame.error: video system not initialized
在pygame写游戏出现pygame.error: video system not initialized 源代码 import sysimport pygamedef run_game(): py ...
- python中video system not initialized怎么解决
今天在github上找到一个用pygame做的Python游戏,但是clone到本地运行的时候却冒出了“mixer system not initialized”这样的问题.其实这句话说的就是音频混音 ...
- Codeforces Round #481 (Div. 3)
我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...
- Codeforces Round #481 (Div. 3)题解
成功掉到灰,真的心太累了,orz!!!!,不是很懂那些国外大佬为什么每次都是20多分钟AK的,QAQ A. Remove Duplicates time limit per test 1 second ...
- coedforces #481Div(3)(ABCDEFG)
A. Remove Duplicates Petya has an array aconsisting of nintegers. He wants to remove duplicate (equa ...
- CodeForces Round#480 div3 第2场
这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...
随机推荐
- Android 实现朋友圈有图片和视频
最近开发比较烦,这个作为我第一篇博客吧. 效果就是图上的样子. 首先是布局文件,没什么就是一个RecycleView <android.support.v7.widget.RecyclerVie ...
- Android Vmp加固实现流程图
0x00: 目前各种加固都说是VMP了,简单分析市面上的加固,然后自己实现了一个类似原理的加固,大致流程图如下: 加固端: 解释器:
- Android中关于XML的一个小问题——使用XML输出“<”错误的问题
在 XML 中,有 5 个预定义的实体引用: < < 小于 > > 大于 & & 和号 ' ' 单引号 " " 引号 注释 ...
- Android studio 安装与配置【Android学习入门】
终于下定决心认真学习Android开发了. 之前在很多平台看到很多大牛们学习Android的经验和心得,纸上得来终觉浅. 这里推荐stormzhang老师总结的Android学习之路. 为了防止电脑卡 ...
- 【起航计划 006】2015 起航计划 Android APIDemo的魔鬼步伐 05 App->Activity->Custom Title 自定义标题栏
Android UI缺省的标题栏由android:label 定义,显示在屏幕左上角,Android允许Activity自定义标题栏,使用自定义Layout重新设置标题栏,比如实现Windows Mo ...
- JavaScript平台Platypi悄然登场
几个月前,一个新的JavaScript平台Platypi悄然诞生.它为开发者提供的不仅仅是一套标准的MVC框架而已,由于它是基于TypeScript构建的,因此对开发者而言在熟悉之中透露出与众不同的感 ...
- lucene中文学习地址推荐
Lucene原理与代码分析http://www.cnblogs.com/forfuture1978/category/300665.html Lucene5.5学习(1)-初尝Lucene全文检索引擎 ...
- OMD开源监控软件
参考 Best Monitoring Solution - OMD (Nagios + Check_MK) 官网 mathias-kettner.com OMD labs.consol.de Conf ...
- js关于cookie的各种方法
//删除cookiedelCookie("GroupName");//s20是代表20秒//h是指小时,如12小时则是:h12//d是天数,30天则:d30setCookie(&q ...
- 用户管理的设计--4.jquery的ajax实现登录名的校验
页面效果 鼠标失去焦点时,不需要刷新页面进行校验,判断登录名是否重复. 实现步骤 1.引入struts2-json-plugin-2.5.10.1插件包 2.页面使用jquery的ajax实现后台校验 ...