Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define ALL(x) x.begin(),x.end()
- #define SZ(x) x.size()
- #define PB push_back
- #define MP make_pair
- #define F first
- #define S second
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int,int> PI;
- int n,w,a[1001];
- int main() {
- io;
- cin >> n >> w;
- for(int i = 0; i < n; i++)
- cin >> a[i];
- LL beg = 0,now = 0,ans = -1;
- for(int i = 0; i < n;i++) {
- now += a[i];
- if(now < 0) {
- beg += abs(now);
- ans += abs(now);
- now = 0;
- }
- }
- ans = max(max(now, beg), ans);
- cout << w - ans + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement