Submission #997926

#TimeUsernameProblemLanguageResultExecution timeMemory
997926piOOECigle (COI21_cigle)C++17
100 / 100
180 ms196692 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> d(n); for (int i = 0; i < n; ++i) { cin >> d[i]; } vector dp(n, vector<int>(n + 1)), pref(dp); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { pref[i][j + 1] = max(pref[i][j], dp[i][j]); } // if (i == 7) { // cout << "here!" << endl; // } int bal = 0, mx = 0, cnt = -1; for (int k = i + 1, j = i; k < n; ++k) { int add = 0; if (bal == 0) { add = 1; cnt += 1; } bal += d[k]; while (j >= 0 && bal - d[j] >= 0) { mx = max(mx, cnt + dp[i][j] - add * (j == i)); bal -= d[j--]; } dp[k][i + 1] = mx; if (j >= 0) { dp[k][i + 1] = max(dp[k][i + 1], cnt + pref[i][j + 1]); } } } // cout << dp[7][2] << endl; cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...