Submission #522777

# Submission time Handle Problem Language Result Execution time Memory
522777 2022-02-05T18:40:07 Z LucaDantas Kitchen (BOI19_kitchen) C++17
0 / 100
1 ms 204 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 <= n*k; i++)
		dp[i] = inf;
	dp[0] = 0;

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

	if(dp[n*k] == inf) puts("impossible");
	else printf("%d\n", dp[n*k]-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);
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -