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;
long long n,a[3005];
pair <long long,long long> dp[3005];
long long ps[3005],ans;
int main(){
ios::sync_with_stdio(false);
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i];
ps[i]=ps[i-1]+a[i];
}
for (int i=1;i<=n;i++){
dp[i]=make_pair(ps[i],1);
for (int j=i-1;j>=1;j--){
if (ps[i]-ps[j] >= dp[j].first && (dp[j].second+1 > dp[i].second ||
(dp[i].second == dp[j].second+1 && ps[i]-ps[j] < dp[i].first))){
dp[i]=make_pair(ps[i]-ps[j],dp[j].second+1);
break;
}
}
}
cout << dp[n].second << "\n";
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... |