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 pb push_back
#define F first
#define S second
using namespace std;
typedef long long llong;
const int MOD = 1e9 + 7;
const int MXN = 4e5 + 7;
const llong INF = 1e18 + 7;
int n, dp[3011][3011], ans;
llong a[3011], pref[3011];
vector <int> pos[3011];
int main(){
ios_base::sync_with_stdio(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
dp[1][i] = 1;
pos[i].pb(1);
}
for(int i = 1; i <= n; i++){
for(int j : pos[i]){
for(int k = 1; k <= n; k++){
if(pref[i] - pref[j - 1] <= pref[k] - pref[i]){
dp[i + 1][k] = max(dp[i + 1][k], dp[j][i] + 1);
if(k < n) pos[k].pb(i + 1);
}
}
}
pos[i].clear();
}
for(int i = 1; i <= n; i++){
ans = max(ans, dp[i][n]);
}
cout << ans;
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... |