Submission #298442

# Submission time Handle Problem Language Result Execution time Memory
298442 2020-09-12T21:08:54 Z peuch Kitchen (BOI19_kitchen) C++17
9 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 310;

int n, m, k;
int a[MAXN], b[MAXN];
int sum;
vector<int> aux;
int marc[MAXN * MAXN];
bool flag = 1;

int main(){
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
		flag &= a[i] >= 2;
	}
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
	if(k > m) {
		printf("Impossible\n");
		return 0;
	}
	if(k == m && m == 2) {
		if(b[1] >= n && b[2] >= n && b[1] + b[2] >= sum && flag){
			printf("%d\n", b[1] + b[2] - sum);
			return 0;
		}
		printf("Impossible\n");
		return 0;
	}
	else if(k == m && m == 1){
		if(b[1] >= sum){
			printf("%d\n", b[1] - sum);
			return 0;
		}
		printf("Impossible\n");
		return 0;
	}
	else if(m == 2 && k == 1){
		if(b[1] >= sum && b[2] >= sum){
			printf("%d\n", min(b[1], b[2]) - sum);
			return 0;
		}
		else if(b[1] >= sum || b[2] >= sum){
			printf("%d\n", max(b[1], b[2]) - sum);
			return 0;
		}
		else if(b[1] + b[2] >= sum){
			aux.push_back(0);
			for(int i = 1; i <= n; i++){
				queue<int> aux2;
				for(int j = 0; j < aux.size(); j++){
					if(marc[aux[j] + a[i]]) continue;
					marc[aux[j] + a[i]] = 1;
					aux2.push(aux[j] + a[i]);
				}
				while(!aux2.empty()) {
					aux.push_back(aux2.front());
					aux2.pop();
				}
			}
			sort(aux.begin(), aux.end());
			int k = upper_bound(aux.begin(), aux.end(), b[1]) - aux.begin() - 1;
			if(b[2] >= sum - aux[k]){
				printf("%d\n", b[1] + b[2] - sum);
				return 0;
			}
			else{
				printf("Impossible\n");
				return 0;
			}
		}
		printf("Impossible\n");
		return 0;
	}
	printf("Impossible\n");
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int j = 0; j < aux.size(); j++){
      |                    ~~^~~~~~~~~~~~
kitchen.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%d %d %d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
kitchen.cpp:21:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -