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;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 500005;
ll n,a[N];
ll ans;
ll cur,pre,pre_ehlel,pre_end;
int main(){
IOS
cin>>n;
for(int i=1; i<=n; i++){
cin>>a[i];
}
cur=0;
pre=a[1];
pre_end=1;
ans=1;
int l=2;
while(l<=n){
cur+=a[l];
if(cur>=pre){
for(int i=pre_end+1; i<=l; i++){
if(cur-a[i]>=pre+a[i]){
cur-=a[i];
pre+=a[i];
}
else break;
}
pre_end=l-1;
pre=cur;
ans++;
cur=0;
if(l==n){
cout<<ans;
return 0;
}
}
l++;
}
cout<<ans-1;
}
# | 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... |