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 int long long
const int NM = 3000, inf = 1e9+7;
int n, a[NM+5], pref[NM+5], dp[NM+5][NM+5], ans = 0;
signed main(){
//freopen("SEGMENTS.inp", "r", stdin);
//freopen("SEGMENTS.ans", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i-1]+a[i];
}
for (int j = 1; j <= n; j++)
for (int i = 1; i <= j; i++){
dp[i][j] = (i == 1 ? 1 : -inf);
for (int k = 1; k <= i-1; k++)
if (pref[j]-pref[i-1] >= pref[i-1]-pref[k-1]) dp[i][j] = max(dp[i][j], dp[k][i-1]+1);
if (j == n) ans = max(ans, dp[i][j]);
}
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... |