Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. /**
  2.  *    author:  NEZZ
  3. **/
  4. #include <bits/stdc++.h>
  5. #define rep(i,a,b) for (int i=a;i<b;i++)
  6. #define rep2(i,a,b) for (int i=a;i>=b;i--)
  7. #define mod 1000000007
  8. #define f first
  9. #define s second
  10. #define endl '\n'
  11. #define ll long long
  12. #define pii pair <int,int>
  13. #define pll pair <ll,ll>
  14. #define vi vector <int>
  15. #define vl vector <ll>
  16. #define vll vector < pll >
  17. #define vii vector < pii >
  18. #define vb  vector <bool>
  19. #define pb push_back
  20. #define mk make_pair
  21. #define sz(a) a.size()
  22. #define all(a) a.begin(),a.end()
  23. #define rall(a) a.rbegin(),a.rend()
  24. #define input freopen("intput","r",stdin)
  25. #define output freopen("output","w",stdout)
  26. #define fastIO ios_base::sync_with_stdio (0),cin.tie(0)
  27. #define debug input,output
  28.  
  29.  
  30. using namespace std;
  31. void affiche (int t[],int n){ rep (i,0,n) cout<<t[i]<<" ";cout<<endl;}
  32. void afficheV (vi t){rep (i,0,sz(t))cout<<t[i]<<" ";cout<<endl;}
  33.  
  34. int main (){
  35.  fastIO;
  36.   int n,d;
  37.   cin>>n>>d;
  38.   int t[n];
  39.   ll sum[n];
  40.   bool cond=true;
  41.   int c=0;
  42.   rep (i,0,n){
  43.   cin>>t[i];
  44.    if (i==0)
  45.      sum[i]=t[i];
  46.    else sum[i]=sum[i-1]+t[i];
  47.    if (t[i]==0){
  48.     c+=(sum[i]<0);
  49.    }
  50.    if (sum[i]>d)
  51.     cond=false;
  52.   }
  53.   if (cond)
  54.        cout<<c;
  55. else cout<<-1;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement