This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 5e5+5;
ll a[mxn];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin>>n;
for(int i=1; i<=n; i++){
cin>>a[i];
a[i]+=a[i-1];
}
int cnt = 0, ptr = 0;
ll prev = 0;
while(true){
//cerr<<cnt<<" "<<ptr<<" "<<prev<<": ";
auto it = lower_bound(a+1+ptr,a+1+n,prev+a[ptr])-a;
ll now = a[it]-a[ptr];
//cerr<<it<<" "<<now<<"\n";
while(ptr+1<it){
ll mov = a[ptr+1]-a[ptr];
if(now-mov<prev+mov)break;
now -= mov;
prev += mov;
//cerr<<mov<<" "<<now<<" "<<prev<<" "<<ptr<<"\n";
ptr++;
}
//cerr<<now<<" "<<prev<<" "<<ptr<<"\n";
prev = a[it]-a[ptr];
ptr = it;
cnt++;
if(ptr>=n)break;
}
cout<<cnt<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |