답안 #522779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522779 2022-02-05T18:53:14 Z LucaDantas Kitchen (BOI19_kitchen) C++17
0 / 100
24 ms 652 KB
#include <cstdio>

constexpr int maxn = 310, inf = 0x3f3f3f3f;

int a[maxn], b[maxn];

int dp[maxn*maxn];

int main() {
	int n, m, k; scanf("%d %d %d", &n, &m, &k);
	for(int i = 0; i < n; i++)
		scanf("%d", a+i);
	for(int i = 0; i < m; i++)
		scanf("%d", b+i);

	int soma = 0;
	for(int i = 0; i < n; i++) {
		soma += a[i];
		if(a[i] < k) return puts("impossible"), 0;
	}

	auto max = [](int a, int b) { return a > b ? a : b; };
	auto min = [](int a, int b) { return a < b ? a : b; };

	for(int i = 0; i < maxn*maxn; i++)
		dp[i] = inf;
	dp[0] = 0;

	for(int i = 0; i < m; i++)
		for(int j = maxn*maxn - 1 - min(n, b[i]); j >= 0; j--)
			dp[j+min(n,b[i])] = min(dp[j+min(n,b[i])], dp[j] + b[i]);

	int opa = inf;
	for(int j = n*k; j < maxn*maxn; j++)
		if(dp[j] >= soma) opa = min(opa, dp[j]);

	if(opa == inf) puts("impossible");
	else printf("%d\n", opa-soma);
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:22:7: warning: variable 'max' set but not used [-Wunused-but-set-variable]
   22 |  auto max = [](int a, int b) { return a > b ? a : b; };
      |       ^~~
kitchen.cpp:10:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  int n, m, k; scanf("%d %d %d", &n, &m, &k);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d", a+i);
      |   ~~~~~^~~~~~~~~~~
kitchen.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d", b+i);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Incorrect 1 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Incorrect 1 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 648 KB Output is correct
2 Correct 20 ms 648 KB Output is correct
3 Correct 24 ms 652 KB Output is correct
4 Correct 24 ms 652 KB Output is correct
5 Incorrect 23 ms 648 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 4 ms 648 KB Output is correct
4 Correct 4 ms 588 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Incorrect 1 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -