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;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<int> bricks(n);
for (int &x : bricks) cin >> x;
vector dp(n+1, vector(n+1, 0));
for (int i = 0; i <= n; i++) {
for (int j = 1; j < i; j++) {
dp[j][i] = max(dp[j][i], dp[j-1][i]);
}
int balance = 0;
int matches = 0;
int current = 0;
for (int k = i+1, j = i; k <= n; k++) {
balance += bricks[k-1];
while (j > 0 && balance - bricks[j-1] >= 0) {
balance -= bricks[--j];
}
dp[i][k] = max(dp[i][k-1], current);
if (balance == 0) {
matches++;
if (j > 0) current = max(current, dp[j-1][i] + matches);
}
}
}
cout << dp[n-1][n] << endl;
}
# | 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... |