답안 #124887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124887 2019-07-04T05:29:17 Z 김세빈(#3048) Kitchen (BOI19_kitchen) C++14
100 / 100
30 ms 1148 KB
#include <bits/stdc++.h>

using namespace std;

int D1[101010], D2[101010];
int n, m, k, s, ans;

void die() { printf("Impossible\n"); exit(0); }

int main()
{
	int i, j, x;
	
	scanf("%d%d%d", &n, &m, &k);
	
	for(i=1; i<=n; i++){
		scanf("%d", &x);
		if(x < k) die();
		s += x;
	}
	
	D1[0] = 1;
	
	for(i=1; i<=1e5; i++){
		D2[i] = -1e9;
	}
	
	for(i=1; i<=m; i++){
		scanf("%d", &x);
		if(x < n){
			for(j=1e5; j>=x; j--){
				if(D1[j - x]) D1[j] = 1;
			}
		}
		else{
			for(j=1e5; j>=x; j--){
				D2[j] = max(D2[j], D2[j - x] + 1);
			}
		}
	}
	
	for(i=1e5; i>=0; i--){
		if(D1[i]) D1[i] = i;
		else D1[i] = D1[i + 1];
	}
	
	ans = 1e9;
	
	for(i=0; i<=1e5; i++){
		if(D2[i] < 0) continue;
		x = max(s - i, (k - D2[i]) * n);
		if(x > 1e5 || D1[x] < x) continue;
		ans = min(ans, D1[x] + i - s);
	}
	
	if(ans == 1e9) die();
	
	printf("%d\n", ans);
	
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
   ~~~~~^~~~~~~~~~
kitchen.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1148 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1148 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 1116 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1144 KB Output is correct
2 Correct 24 ms 1144 KB Output is correct
3 Correct 28 ms 1140 KB Output is correct
4 Correct 30 ms 1144 KB Output is correct
5 Correct 28 ms 1144 KB Output is correct
6 Correct 23 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1144 KB Output is correct
2 Correct 7 ms 1144 KB Output is correct
3 Correct 7 ms 1148 KB Output is correct
4 Correct 7 ms 1144 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1148 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 1116 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 27 ms 1144 KB Output is correct
15 Correct 24 ms 1144 KB Output is correct
16 Correct 28 ms 1140 KB Output is correct
17 Correct 30 ms 1144 KB Output is correct
18 Correct 28 ms 1144 KB Output is correct
19 Correct 23 ms 1144 KB Output is correct
20 Correct 7 ms 1144 KB Output is correct
21 Correct 7 ms 1144 KB Output is correct
22 Correct 7 ms 1148 KB Output is correct
23 Correct 7 ms 1144 KB Output is correct
24 Correct 2 ms 420 KB Output is correct
25 Correct 23 ms 1144 KB Output is correct
26 Correct 26 ms 1144 KB Output is correct
27 Correct 18 ms 1144 KB Output is correct
28 Correct 25 ms 1144 KB Output is correct
29 Correct 27 ms 1144 KB Output is correct
30 Correct 30 ms 1144 KB Output is correct