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;
int main() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<ll>pr(n+1);
for(int i=0;i<n;i++)pr[i+1]=pr[i]+a[i];
vector<int>ans(n);
vector<ll> ans_sum(n);
ll sum=0;
for(int i=0;i<n;i++){
sum+=a[i];
ans_sum[i]=sum;
ans[i]=1;
}
for(int i=0;i<n;i++){
sum=0;
for(int j=i;j>0;j--){
if(pr[i+1]-pr[j]>=ans_sum[j-1]){
if(ans[i]<ans[j-1]+1){
ans[i]=ans[j-1]+1;
ans_sum[i]=pr[i+1]-pr[j];
}
if(ans[i]==ans[j-1]+1){
ans_sum[i]=min(ans_sum[i],pr[i+1]-pr[j]);
}
}
}
}
cout<<ans[n-1];
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... |