|
|
back to boardO(n) Solution Subtract 1 from each element Apply window to the array for max sum of S #include <bits/stdc++.h> using namespace std; #define repl(i,x,n) for(long long i=(long long)(x);i<(long long)(n);i++) #define rep(i,x,n) for(long i=long(x);i<long(n);i++) int main() { //ifstream cin("input.in"); //ofstream cout("output.out"); ios::sync_with_stdio(0);cin.tie(0); long n,s,a[100009],p=0; cin>>n>>s; bool flag=1; rep(i,0,n) { cin>>a[i]; a[i]--; } rep(i,0,n) { p+=a[i]; if(p>s) flag=0; p=max(p,0l); } if(flag) cout<<"YES"; else cout<<"NO"; } Edited by author 11.12.2017 08:23 |
|
|