제출 #5157

#제출 시각아이디문제언어결과실행 시간메모리
5157aintaK개의 묶음 (IZhO14_blocks)C++98
100 / 100
132 ms41716 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...