답안 #5159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5159 2014-02-11T18:34:43 Z cki86201 K개의 묶음 (IZhO14_blocks) C++
0 / 100
0 ms 41440 KB
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> Pi;

int n, k, inp[100010];
int d[102][100010];

int main()
{
	freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&k);
	int i, j;
	for(i=1;i<=n;i++)scanf("%d",inp+i);
	for(i=1;i<=n;i++)d[1][i] = max(d[1][i-1], inp[i]);
	for(i=2;i<=k;i++){
		vector <Pi> v;
		for(j=i;j<=n;j++){
			int now = d[i-1][j-1];
			while(!v.empty() && v.back().X < inp[j])now = min(now, v.back().Y), v.pop_back();
			if(v.empty() || v.back().X + v.back().Y > inp[j] + now)v.push_back(Pi(inp[j],now));
			d[i][j] = v.back().X + v.back().Y;
		}
	}
	printf("%d",d[k][n]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 41440 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 41440 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 41440 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 41440 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -