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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <int> a(n+1),p(n+1),ind(n+1),ans(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)p[i]=p[i-1]+a[i];
for(int i=1;i<=n;i++){
ind[i]=max(ind[i],ind[i-1]);
ans[i]=ans[ind[i]]+1;
int cur=p[i]-p[ind[i]];
//cout<<ind[i]<<" "<<ans[ind[i]]<<" "<<ans[i]<<"\n";
int l=i,r=n;
int p_ind=0;
while(l<=r){
int md=(l+r)/2;
if(p[md]-p[i]>=cur){
p_ind=md;
r=md-1;
}
else l=md+1;
}
ind[p_ind]=i;
}
cout<<ans[n]<<"\n";
}
/*
4
2 3 1 7
5
6 2 3 9 13
3
3 1 2
5
1 12 11 46 47
*/
# | 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... |