답안 #724032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724032 2023-04-14T15:50:14 Z lovrot Kitchen (BOI19_kitchen) C++17
100 / 100
37 ms 1108 KB
#include <cstdio>
#include <algorithm>

using namespace std; 

const int N = 310;
const int INF = 2e9;

int n, m, k, A[N], B[N]; 
int dp[2][N * N]; 

int main() {
	for(int i = 0; i < N * N; i++) dp[0][i] = -INF; 
	dp[0][0] = 0;

	scanf("%d%d%d", &n, &m, &k); 
	int nim = INF, sum = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d", A + i); 
		nim = min(nim, A[i]); 
		sum += A[i]; 
	}
	for(int i = 0; i < m; i++) scanf("%d", B + i); 

	if(nim < k) {
		printf("Impossible\n");
		return 0; 
	}

	bool f = 0;
	int _sum = 0;
	for(int i = 0; i < m; i++) {
		f ^= 1;
		_sum += B[i]; 
		for(int j = 0; j < N * N; j++) {
			dp[f][j] = dp[!f][j];
			if(B[i] <= j) dp[f][j] = max(dp[f][j],  dp[!f][j - B[i]] + min(n, B[i])); 
		}
	}
	for(int i = sum; i < N * N; i++) 
		if(dp[f][i] >= n * k) {
			printf("%d\n", i - sum); 
			return 0; 
		}
	printf("Impossible\n");
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
kitchen.cpp:23:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  for(int i = 0; i < m; i++) scanf("%d", B + i);
      |                             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 980 KB Output is correct
2 Correct 28 ms 1028 KB Output is correct
3 Correct 36 ms 980 KB Output is correct
4 Correct 37 ms 980 KB Output is correct
5 Correct 36 ms 916 KB Output is correct
6 Correct 25 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 6 ms 980 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 6 ms 980 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 980 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 32 ms 980 KB Output is correct
15 Correct 28 ms 1028 KB Output is correct
16 Correct 36 ms 980 KB Output is correct
17 Correct 37 ms 980 KB Output is correct
18 Correct 36 ms 916 KB Output is correct
19 Correct 25 ms 1016 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 6 ms 980 KB Output is correct
22 Correct 5 ms 980 KB Output is correct
23 Correct 6 ms 980 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 25 ms 980 KB Output is correct
26 Correct 29 ms 980 KB Output is correct
27 Correct 21 ms 920 KB Output is correct
28 Correct 30 ms 916 KB Output is correct
29 Correct 30 ms 980 KB Output is correct
30 Correct 37 ms 1016 KB Output is correct