# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529951 | tht2005 | K개의 묶음 (IZhO14_blocks) | C++17 | 99 ms | 2928 KiB |
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;
const int N = 100005;
const int INF = 0x3f3f3f3f;
int n, kk, a[N], L[N], f[N], g[N], h[N];
int main() {
scanf("%d %d", &n, &kk);
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
int k = i - 1;
while(k > 0 && a[i] >= a[k])
k = L[k];
L[i] = k;
}
f[0] = 0;
for(int i = 1; i <= n; ++i)
f[i] = max(f[i - 1], a[i]);
for(int i = 2; i <= kk; ++i) {
for(int j = 0; j <= n; ++j) {
g[j] = f[j];
f[j] = INF;
}
h[i - 1] = INF;
for(int j = i; j <= n; ++j) {
h[j] = g[j - 1];
for(int k = j - 1; k > L[j]; k = L[k])
h[j] = min(h[j], h[k]);
f[j] = min(f[L[j]], h[j] + a[j]);
}
}
printf("%d", f[n]);
return 0;
}
Compilation message (stderr)
# | 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... |