답안 #6011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6011 2014-06-15T07:51:12 Z imsifile 스트랩 (JOI14_straps) C++
100 / 100
0 ms 1128 KB
#include<stdio.h>
#include<algorithm>
using namespace std;

int n, sok=1, ba1[2010], sum[2010], ba2[2010][2], dy[2010], acn, bcn, pre, dap;

int mx(int p, int q){
	if(!p)return q;
	else if(!q)return p;
	return p>q?p:q;
}

int main(){
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d%d", &j, &k);
		if(j && k>=0)sok+=j-1, pre+=k;
		else if(j>1)ba2[bcn][0]=j-1, ba2[bcn++][1]=k;
		else if(k>0)ba1[acn++]=k;
	}
	sort(ba1, ba1+acn);
	if(sok>acn)sok=acn;
	for(i=1; i<=acn; i++)sum[i]=sum[i-1]+ba1[acn-i];
	for(i=0; i<bcn; i++){
		for(j=acn-sok; j>0; j--){
			if(j<=ba2[i][0])dy[j]=mx(dy[j], ba2[i][1]);
			else if(dy[j-ba2[i][0]])dy[j]=mx(dy[j], dy[j-ba2[i][0]]+ba2[i][1]);
		}
	}
	for(i=0; i<=acn-sok; i++){
		if(!dy[i] && i)continue;
		if(dap<pre+sum[sok+i]+dy[i])dap=pre+sum[sok+i]+dy[i];
	}
	printf("%d", dap);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1128 KB Output is correct
2 Correct 0 ms 1128 KB Output is correct
3 Correct 0 ms 1128 KB Output is correct
4 Correct 0 ms 1128 KB Output is correct
5 Correct 0 ms 1128 KB Output is correct
6 Correct 0 ms 1128 KB Output is correct
7 Correct 0 ms 1128 KB Output is correct
8 Correct 0 ms 1128 KB Output is correct
9 Correct 0 ms 1128 KB Output is correct
10 Correct 0 ms 1128 KB Output is correct
11 Correct 0 ms 1128 KB Output is correct
12 Correct 0 ms 1128 KB Output is correct
13 Correct 0 ms 1128 KB Output is correct
14 Correct 0 ms 1128 KB Output is correct
15 Correct 0 ms 1128 KB Output is correct
16 Correct 0 ms 1128 KB Output is correct
17 Correct 0 ms 1128 KB Output is correct
18 Correct 0 ms 1128 KB Output is correct
19 Correct 0 ms 1128 KB Output is correct
20 Correct 0 ms 1128 KB Output is correct
21 Correct 0 ms 1128 KB Output is correct
22 Correct 0 ms 1128 KB Output is correct
23 Correct 0 ms 1128 KB Output is correct
24 Correct 0 ms 1128 KB Output is correct
25 Correct 0 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1128 KB Output is correct
2 Correct 0 ms 1128 KB Output is correct
3 Correct 0 ms 1128 KB Output is correct
4 Correct 0 ms 1128 KB Output is correct
5 Correct 0 ms 1128 KB Output is correct
6 Correct 0 ms 1128 KB Output is correct
7 Correct 0 ms 1128 KB Output is correct
8 Correct 0 ms 1128 KB Output is correct
9 Correct 0 ms 1128 KB Output is correct
10 Correct 0 ms 1128 KB Output is correct
11 Correct 0 ms 1128 KB Output is correct
12 Correct 0 ms 1128 KB Output is correct
13 Correct 0 ms 1128 KB Output is correct
14 Correct 0 ms 1128 KB Output is correct
15 Correct 0 ms 1128 KB Output is correct
16 Correct 0 ms 1128 KB Output is correct
17 Correct 0 ms 1128 KB Output is correct
18 Correct 0 ms 1128 KB Output is correct
19 Correct 0 ms 1128 KB Output is correct
20 Correct 0 ms 1128 KB Output is correct
21 Correct 0 ms 1128 KB Output is correct
22 Correct 0 ms 1128 KB Output is correct
23 Correct 0 ms 1128 KB Output is correct
24 Correct 0 ms 1128 KB Output is correct
25 Correct 0 ms 1128 KB Output is correct
26 Correct 0 ms 1128 KB Output is correct
27 Correct 0 ms 1128 KB Output is correct
28 Correct 0 ms 1128 KB Output is correct
29 Correct 0 ms 1128 KB Output is correct
30 Correct 0 ms 1128 KB Output is correct
31 Correct 0 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1128 KB Output is correct
2 Correct 0 ms 1128 KB Output is correct
3 Correct 0 ms 1128 KB Output is correct
4 Correct 0 ms 1128 KB Output is correct
5 Correct 0 ms 1128 KB Output is correct
6 Correct 0 ms 1128 KB Output is correct
7 Correct 0 ms 1128 KB Output is correct
8 Correct 0 ms 1128 KB Output is correct
9 Correct 0 ms 1128 KB Output is correct
10 Correct 0 ms 1128 KB Output is correct
11 Correct 0 ms 1128 KB Output is correct
12 Correct 0 ms 1128 KB Output is correct
13 Correct 0 ms 1128 KB Output is correct
14 Correct 0 ms 1128 KB Output is correct
15 Correct 0 ms 1128 KB Output is correct
16 Correct 0 ms 1128 KB Output is correct
17 Correct 0 ms 1128 KB Output is correct
18 Correct 0 ms 1128 KB Output is correct
19 Correct 0 ms 1128 KB Output is correct
20 Correct 0 ms 1128 KB Output is correct
21 Correct 0 ms 1128 KB Output is correct
22 Correct 0 ms 1128 KB Output is correct
23 Correct 0 ms 1128 KB Output is correct
24 Correct 0 ms 1128 KB Output is correct
25 Correct 0 ms 1128 KB Output is correct
26 Correct 0 ms 1128 KB Output is correct
27 Correct 0 ms 1128 KB Output is correct
28 Correct 0 ms 1128 KB Output is correct
29 Correct 0 ms 1128 KB Output is correct
30 Correct 0 ms 1128 KB Output is correct
31 Correct 0 ms 1128 KB Output is correct
32 Correct 0 ms 1128 KB Output is correct
33 Correct 0 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1128 KB Output is correct
2 Correct 0 ms 1128 KB Output is correct
3 Correct 0 ms 1128 KB Output is correct
4 Correct 0 ms 1128 KB Output is correct
5 Correct 0 ms 1128 KB Output is correct
6 Correct 0 ms 1128 KB Output is correct
7 Correct 0 ms 1128 KB Output is correct
8 Correct 0 ms 1128 KB Output is correct
9 Correct 0 ms 1128 KB Output is correct
10 Correct 0 ms 1128 KB Output is correct
11 Correct 0 ms 1128 KB Output is correct
12 Correct 0 ms 1128 KB Output is correct
13 Correct 0 ms 1128 KB Output is correct
14 Correct 0 ms 1128 KB Output is correct
15 Correct 0 ms 1128 KB Output is correct
16 Correct 0 ms 1128 KB Output is correct
17 Correct 0 ms 1128 KB Output is correct
18 Correct 0 ms 1128 KB Output is correct
19 Correct 0 ms 1128 KB Output is correct
20 Correct 0 ms 1128 KB Output is correct
21 Correct 0 ms 1128 KB Output is correct
22 Correct 0 ms 1128 KB Output is correct
23 Correct 0 ms 1128 KB Output is correct
24 Correct 0 ms 1128 KB Output is correct
25 Correct 0 ms 1128 KB Output is correct