mirror of https://github.com/cyp0633/homework.git
CSP 3-15 bus 公交系统
This commit is contained in:
parent
4cc004570b
commit
4afc4e7e1c
|
@ -0,0 +1,23 @@
|
|||
//公交系统
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int change, count = 0, capacity, n, maxNum = 0, minNum = 0;
|
||||
scanf("%d %d", &n, &capacity);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &change);
|
||||
count += change;
|
||||
maxNum = maxNum > count ? maxNum : count;
|
||||
minNum = minNum < count ? minNum : count;
|
||||
}
|
||||
if (minNum * -1 > capacity || maxNum > capacity)
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
printf("%d", capacity - maxNum + 1 + minNum);
|
||||
}
|
Loading…
Reference in New Issue