답안 #124851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124851 2019-07-04T04:27:11 Z 윤교준(#3050) Kitchen (BOI19_kitchen) C++14
9 / 100
28 ms 1016 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
inline void fuk() { puts("Impossible"); exit(0); }

bitset<1605> D[1605];

int A[44], B[44];

int N, M, K, Asum;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	if(M < K) fuk();
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		if(A[i] < K) fuk();
		Asum += A[i];
	}
	for(int i = 1; i <= M; i++) cin >> B[i];
	sort(B+1, B+M+1);

	if(1 == M) {
		if(Asum <= B[1]) {
			cout << B[1]-Asum << endl;
			exit(0);
		}
		fuk();
	}
	if(2 == M) {
		if(1 == K) {
			if(Asum <= B[1]) {
				cout << B[1]-Asum << endl;
				exit(0);
			}
			if(Asum <= B[2]) {
				cout << B[2]-Asum << endl;
				exit(0);
			}
			if(Asum <= B[1]+B[2]) {
				cout << B[1]+B[2] - Asum << endl;
				exit(0);
			}
			fuk();
		}
		if(Asum <= B[1]+B[2] && N <= min(B[1], B[2])) {
			cout << B[1]+B[2] - Asum << endl;
			exit(0);
		}
		fuk();
	}

	D[0][0] = true;
	for(int i = 1, sum = 0; i <= M; i++) {
		for(int bsum = sum; 0 <= bsum; bsum--) {
			for(int cnt = N*K; cnt--;)
				if(D[bsum][cnt])
					D[bsum+B[i]][min(N*K, cnt + min(B[i], N))] = true;
		}
		sum += B[i];
	}

	for(int i = Asum; i < 1605; i++)
		if(D[i][N*K]) {
			cout << i-Asum << endl;
			exit(0);
		}
	fuk();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 608 KB Output is correct
2 Correct 14 ms 504 KB Output is correct
3 Incorrect 27 ms 504 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -