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;
const int MAX_N = 5000;
int d[MAX_N + 1], sd[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1];
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
cin >> d[i];
sd[i] = sd[i - 1] + d[i];
}
for ( int i = 1; i <= n; i++ ) {
int k = i, c = 0;
for ( int j = i + 1; j <= n; j++ ) {
while ( k > 0 && sd[i] - sd[k] < sd[j] - sd[i] )
k--;
dp[i][j] = max( dp[i][j], dp[k][i] + c );
if ( sd[i] - sd[k] == sd[j] - sd[i] )
c++;
}
for ( int j = i; j <= n; j++ )
dp[i][j] = max( dp[i][j], max( dp[i - 1][j], dp[i][j - 1] ) );
}
int ans = 0;
for ( int i = 0; 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... |