Advertisement
amine99

Untitled

May 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  4. #define ALL(x) x.begin(),x.end()
  5. #define SZ(x) x.size()
  6. #define PB push_back
  7. #define MP make_pair
  8. #define F first
  9. #define S second
  10. typedef long long LL;
  11. typedef vector<int> VI;
  12. typedef pair<int,int> PI;
  13.  
  14. int n,w,x;
  15. LL beg,now,ans=-1;
  16.  
  17. int main() {
  18.    io;
  19.    cin >> n >> w;
  20.    for(int i = 0; i < n; i++) {
  21.       cin >> x;
  22.       now += x;
  23.       if(now < 0) {
  24.          beg += abs(now);
  25.          ans += abs(now);
  26.          now = 0;
  27.       }
  28.       ans = max(max(now, beg),ans);
  29.       if(beg > w || now > w) {
  30.          puts("0");
  31.          exit(0);
  32.       }
  33.    }
  34.    cout << w - ans + 1;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement