Submission #340179

#TimeUsernameProblemLanguageResultExecution timeMemory
340179_aniK blocks (IZhO14_blocks)C++17
0 / 100
1 ms492 KiB
#define BUGO(x) cerr << #x << " = " << (x) << '\n'; #include <iostream> #include <algorithm> using namespace std; int dp[100'002][102], a[100'002], pref[100'002]; int mx[4 * 100'002]; void Build(int v, int vl, int vr) { if (vl == vr) { mx[v] = a[vl]; return; } int m = (vl + vr) / 2; Build(v * 2, vl, m); Build(v * 2 + 1, m + 1, vr); mx[v] = max(mx[v * 2], mx[v * 2 + 1]); } int Mx(int v, int vl, int vr, int l, int r) { if (vl == vr) return mx[v]; int res = 0; int m = (vl + vr) / 2; if (l <= m) res = max(res, Mx(v * 2, vl, m, l, min(r, m))); if (r > m)res = max(res, Mx(v * 2 + 1, m + 1, vr, max(l, m + 1), r)); return res; } int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; Build(1, 1, n); for (int i = 1; i <= n; i++) for (int curk = 1; curk <= k; curk++) dp[i][curk] = 1'000'000'000; dp[1][1] = a[1]; for (int i = 2; i <= n; i++) for (int curk = max(1, k - n + i); curk <= min(i, k - ((n - i) ? 1 : 0)); curk++) for (int sz = 1; sz < i - curk + 1; sz++) { /* if (i == 3) { BUGO(curk); BUGO(sz); }*/ dp[i][curk] = min(dp[i][curk], dp[i - sz][curk - 1] + Mx(1, 1, n, i - sz + 1, i)); } /*for (int i = 1; i <= n; i++) { for (int curk = 0; curk <= k; curk++) cerr << dp[i][curk] << ' '; cerr << '\n'; }*/ cout << dp[n][k] << '\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...