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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e3 + 5;
int n;
int a[N], dp[N][N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int res = 0;
for (int i = 2; i <= n; ++i) {
int k = i - 1, s = a[i - 1], t = 0, cnt = 0;
dp[i][i] = dp[i - 1][i - 1];
for (int j = i + 1; j <= n; ++j) {
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
t += a[j - 1];
while (k && s <= t) {
cnt += s == t;
s += a[--k];
}
if (k) {
dp[i][j] = max(dp[i][j], dp[k][i - 1] + cnt);
}
res = max(res, dp[i][j]);
}
for (int j = 1; j <= i; ++j) {
dp[j][i] = max(dp[j][i], dp[j - 1][i]);
}
}
cout << res;
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... |