CF978E.Bus Video System
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y−x. So the system records show how number of passengers changed.
The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a1,a2,…,an (exactly one number for each bus stop), where ai is the record for the bus stop i. The bus stops are numbered from 1 to n 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 w (that is, at any time in the bus there should be from 0 to w passengers inclusive).
贝尔兰的公交车配备了视频监控系统。该系统记录每次公交站点上下车后车上乘客数量的变化情况。
若 x 表示公交车在当前站点停靠前的乘客人数,y 表示公交车在当前站点停靠后的乘客人数,则系统记录数值 y−x。因此,系统记录反映的是乘客人数的变化量。
本次测试运行针对一辆公交车和 n 个公交站点进行。因此,系统记录了一组整数序列 a1,a2,…,an(每个站点恰好对应一个数),其中 ai 是第 i 个站点的记录值。公交站点按时间顺序编号为 1 至 n。
请确定:在公交车容量为 w(即任意时刻车上乘客人数必须在 0 到 w 之间,含端点)的前提下,公交车在第一个站点停靠前可能的乘客人数有多少种取值?
输入格式
The first line contains two integers n and w (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,…,an (−106≤ai≤106), where ai equals to the number, which has been recorded by the video system after the i-th bus stop.
第一行包含两个整数 n 和 w (1≤n≤1000,1≤w≤109) —— 分别表示公交站点的数量和公交车的容量。
第二行包含一个序列 a1,a2,…,an (−106≤ai≤106),其中 ai 表示视频系统在第 i 个公交站点之后记录的数值。
输出格式
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 w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
打印在第一个公交站之前车上可能的乘客人数的方案数,已知公交车的容量为 w。如果该情况自相矛盾(即:无论初始乘客数取何值,都会出现矛盾),则输出 0。
输入输出样例
输入#1
3 5 2 1 -3
输出#1
3
输入#2
2 4 -1 1
输出#2
4
输入#3
4 10 2 4 1 2
输出#3
2
说明/提示
In the first example initially in the bus could be 0, 1 or 2 passengers.
In the second example initially in the bus could be 1, 2, 3 or 4 passengers.
In the third example initially in the bus could be 0 or 1 passenger.
在第一个例子中,公交车上最初可能有 0、1 或 2 名乘客。
在第二个例子中,公交车上最初可能有 1、2、3 或 4 名乘客。
在第三个例子中,公交车上最初可能有 0 或 1 名乘客。
输入解题思路,AI测评打分。不知道怎么写?