Submission #858322

# Submission time Handle Problem Language Result Execution time Memory
858322 2023-10-08T06:11:45 Z Trisanu_Das Kitchen (BOI19_kitchen) C++17
51 / 100
12 ms 796 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXV  = 1e5 + 10;
 
int dp[MAXV];
int a[310], b[310];
int n, m, k;
int main(){
	scanf("%d %d %d", &n, &m, &k);
	int soma = 0, mina = 1e9 + 7;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		mina = min(mina, a[i]);
		soma += a[i];
	}
	for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
	if(mina < k){
		printf("Impossible\n");
		return 0;
	}
 
	if(k == 1){
		dp[0] = 1;
		for(int i = 1; i <= m; i++){
			for(int j = 90000 - b[i]; j >= 0; j--){
				dp[j + b[i]] |= dp[j];
			}
		}
		for(int i = soma; i <= 90000; i++){
			if(dp[i]){
				printf("%d\n", i -soma);
				return 0;
			}
		}
		printf("Impossible\n");
	}
	else{
		int ans = 1e9 + 7;
		for(int i = 0; i <(1<<m); i++){
			if(__builtin_popcount(i) < k) continue;
			int lsoma = 0;
			int chefmin = n*k;
			int cheftot = 0;
			for(int j = 1; j <= m; j++){
				if((1<<(j-1))&i) lsoma += b[j],cheftot += min(n,b[j]); 
			}
			if(cheftot >= chefmin && lsoma >= soma){
				ans = min(lsoma - soma, ans);
			}
		}
		if(ans == 1e9 + 7){
			printf("Impossible\n");
			return 0;
		}
		printf("%d\n", ans);
	}
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  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:16:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 440 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 604 KB Output is correct
2 Correct 9 ms 796 KB Output is correct
3 Correct 12 ms 792 KB Output is correct
4 Correct 12 ms 792 KB Output is correct
5 Correct 12 ms 604 KB Output is correct
6 Correct 11 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 440 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 11 ms 604 KB Output is correct
15 Correct 9 ms 796 KB Output is correct
16 Correct 12 ms 792 KB Output is correct
17 Correct 12 ms 792 KB Output is correct
18 Correct 12 ms 604 KB Output is correct
19 Correct 11 ms 792 KB Output is correct
20 Incorrect 1 ms 344 KB Output isn't correct
21 Halted 0 ms 0 KB -