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<stdio.h>
int D[101][100010];
int n, m, w[100010], st[100010][2];
int main()
{
int i, j, top, x;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++){
scanf("%d", &w[i]);
D[1][i] = w[i];
if (i > 1 && D[1][i] < D[1][i - 1])D[1][i] = D[1][i - 1];
}
for (i = 1; i < m; i++){
top = 0;
for (j = i + 1; j <= n; j++){
x = D[i][j - 1];
while (top && st[top][0] <= w[j]){
if (x>st[top][1])x = st[top][1];
top--;
}
if (!top || x + w[j] < st[top][0] + st[top][1])st[++top][0] = w[j], st[top][1] = x;
D[i + 1][j] = st[top][0] + st[top][1];
}
}
printf("%d\n", D[m][n]);
}
# | 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... |