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 x first
#define y second
#define sz(a) a.size()
typedef long long ll;
const int N = 5e3 + 7;
int a[N];
ll dp[N][N], mx[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i - 1; ++j) {
mx[j] = dp[j][i - 1];
}
for (int j = 1; j <= i - 1; ++j) {
mx[j] = max(mx[j], mx[j - 1]);
}
ll sa = 0;
ll sb = 0;
ll x = 0;
int cnt = 0;
int pos = i - 1;
for (int j = i; j <= n; ++j) {
sb += a[j];
while (pos >= 1 && sa < sb) {
sa += a[pos];
pos--;
}
if (pos > 0 && sa == sb) {
cnt++;
x = max(x, mx[pos] + cnt);
}
dp[i][j + 1] = x;
}
}
ll ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i][n]);
cout << ans << "\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... |