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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<vector<int>> dp(N, vector<int>(N));
for (int mid = N - 1; mid >= 1; mid--) {
for (int i = N - 2; i >= mid; i--) {
dp[mid][i] = max(dp[mid][i], dp[mid][i + 1]);
}
// [mid - 1, mid] as splitting point
int sumLft = 0;
int sumRgt = 0;
int cost = 0;
int ptr = mid;
for (int i = mid - 1; i >= 0; i--) {
sumLft += A[i];
while (ptr < N && sumRgt < sumLft) {
sumRgt += A[ptr];
ptr += 1;
}
cost += (sumLft == sumRgt);
if (i > 0 && ptr < N) {
dp[i - 1][mid - 1] = max(dp[i - 1][mid - 1], dp[mid][ptr] + cost);
}
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
ans = max(ans, dp[0][i]);
}
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... |