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() {
ios_base::sync_with_stdio(0);
cin.tie(0);
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=1;i<n;i++){
for(int j=i-1;j>=0;j--){
if(pr[i+1]>=ans_sum[j]+pr[j+1]){
ans[i]=ans[j]+1;
ans_sum[i]=pr[i+1]-pr[j+1];
break;
}
}
}
for(int i=0;i<n-1;i++){
assert(ans_sum[i]<=ans_sum[i+1]);
}
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... |