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 endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
int main(){
fastio;
int n;
cin>>n;
ll pre[n+1],dp[n+1],ans[n+1];
pre[0]=0;
for(int i=1;i<=n;i++){
ll x;
cin>>x;
pre[i]=pre[i-1]+x;
dp[i]=ans[i]=0;
}
dp[0]=ans[0]=0;
for(int i=1;i<=n;i++){
int lo=0,hi=i-1;
while(hi-lo>1){
int mid=(lo+hi)>>1;
if(pre[i]-pre[mid]>=dp[mid]) lo=mid;
else hi=mid;
}
if(pre[i]-pre[hi]>=dp[hi]){
dp[i]=pre[i]-pre[hi];
ans[i]=ans[hi]+1;
}else if(pre[i]-pre[lo]>=dp[lo]){
dp[i]=pre[i]-pre[lo];
ans[i]=ans[lo]+1;
}else{
dp[i]=pre[i];
ans[i]=1;
}
}
cout<<ans[n]<<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... |