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

input
3 5
2 1 -3
output
3
input
2 4
-1 1
output
4
input
4 10
2 4 1 2
output
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的更多相关文章

  1. CF978E Bus Video System【数学/前缀和/思维】

    [链接]: CF [分析]: 设上车前人数 x ,中途最大人数为 x+max ,最小人数为 x+min (max≥0,min≤0) 可得不等式组 x+max≤w, x+min≥0 整数解个数为 max ...

  2. Bus Video System CodeForces - 978E (思维)

    The busses in Berland are equipped with a video surveillance system. The system records information ...

  3. Codeforces 978E:Bus Video System

    题目链接:http://codeforces.com/problemset/problem/978/E 题意 一辆公交车,在每站会上一些人或下一些人,车的最大容量为w,问初始车上可能有的乘客的情况数. ...

  4. pygame.error: video system not initialized

    在pygame写游戏出现pygame.error: video system not initialized 源代码 import sysimport pygamedef run_game(): py ...

  5. python中video system not initialized怎么解决

    今天在github上找到一个用pygame做的Python游戏,但是clone到本地运行的时候却冒出了“mixer system not initialized”这样的问题.其实这句话说的就是音频混音 ...

  6. Codeforces Round #481 (Div. 3)

    我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...

  7. Codeforces Round #481 (Div. 3)题解

    成功掉到灰,真的心太累了,orz!!!!,不是很懂那些国外大佬为什么每次都是20多分钟AK的,QAQ A. Remove Duplicates time limit per test 1 second ...

  8. coedforces #481Div(3)(ABCDEFG)

    A. Remove Duplicates Petya has an array aconsisting of nintegers. He wants to remove duplicate (equa ...

  9. CodeForces Round#480 div3 第2场

    这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...

随机推荐

  1. SublimeText插件vue Syntax Highlight : vue语法高亮

    参考:http://www.cnblogs.com/cosnyang/p/6290950.html Vue.js 的单文件组件(*.vue)在 sublime 编辑器中是不被识别的.若要想高亮显示,需 ...

  2. CSS3的Animation

    1.animation-name :动画名    2.animation-duration:时间    3.animation-delay:延时    4.animation-iteration-co ...

  3. CSS中的鼠标样式明细

    <INPUT   TYPE="submit"   style="cursor:   hand"   value="hand">  ...

  4. 笨办法学Python(六)

    习题 6: 字符串(string)和文本 虽然你已经在程序中写过字符串了,你还没学过它们的用处.在这章习题中我们将使用复杂的字符串来建立一系列的变量,从中你将学到它们的用途.首先我们解释一下字符串是什 ...

  5. php:定义时间跳转到指定页面

    我们想要定义延迟时间,再跳转到指定页面,只要用header()即可,语法: header("Refresh:延迟时间;url=要跳转的页面"); 例子: 注意注意:我们在heade ...

  6. node实现爬虫

    node实现获取到豆瓣电影排行榜页面. 准备工作: 1.新建一个文件夹node 在当前文件夹中打开cmd 下载 npm install 初始化 npm init(注意一下:如果你的npm init没有 ...

  7. 【BZOJ4555】[TJOI2016&HEOI2016] 求和(NTT)

    点此看题面 大致题意: 计算\(\sum_{i=0}^n\sum_{j=0}^iS(i,j)*2^j*(j!)\),其中\(S\)为第二类斯特林数. 推式子 首先让我们来推一波式子: 因为当\(i&l ...

  8. 在vue中使用animate库

    <style> @keyframes bounce-in { 0% { transform: scale(0); } 50% { transform: scale(1.5) } 100% ...

  9. openstack kilo python cinderclient

    ➜  ~ pythonPython 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on ...

  10. rabbitmq安装使用

    使用 http://www.open-open.com/lib/view/open1325131828249.html ubuntu:apt-get install erlang-noxsudo ap ...