# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28888 | ulna | K blocks (IZhO14_blocks) | C++11 | 213 ms | 64112 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;
// why am I so weak
int n, k;
int a[100055];
int dp[155][100055];
typedef pair<int, int> P;
#define ft first
#define sd second
P p[100055];
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
memset(dp, 63, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= k; i++) {
stack<P> sta;
sta.push(P(0x3f3f3f3f, 0x3f3f3f3f));
for (int j = 1; j <= n; j++) {
int low = dp[i - 1][j - 1];
while (!sta.empty() && sta.top().ft <= a[j]) {
low = min(low, sta.top().sd);
sta.pop();
}
dp[i][j] = min(sta.top().ft + sta.top().sd, a[j] + low);
if (sta.top().ft + sta.top().sd > a[j] + low) {
sta.push(P(a[j], low));
}
}
}
printf("%d\n", dp[k][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... |