Submission #124872

# Submission time Handle Problem Language Result Execution time Memory
124872 2019-07-04T05:00:20 Z 구재현(#3056) Kitchen (BOI19_kitchen) C++14
52 / 100
1000 ms 1184 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
using lint = long long;
using pi = pair<lint, int>;

int n, m, k;
int a[MAXN], b[MAXN];
int dp1[100000];
int dp2[100000];

int main(){
	cin >> n >> m >> k;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(a[i] < k){
			puts("Impossible");
			return 0;
		}
	}
	for(int i=1; i<=m; i++) cin >> b[i];
	sort(b + 1, b + m + 1);
	int acc = accumulate(a + 1, a + n + 1, 0);
	int l = lower_bound(b + 1, b + m + 1, n) - b;
	dp1[0] = 1;
	for(int i=1; i<l; i++){
		for(int j=99999; j>=b[i]; j--){
			dp1[j] |= dp1[j - b[i]];
		}
	}
	dp2[0] = 0;
	fill(dp2 + 1, dp2 + 100000, -1e9);
	for(int i=l; i<=m; i++){
		for(int j=99999; j>=b[i]; j--){
			dp2[j] = max(dp2[j], dp2[j - b[i]] + 1);
		}
	}
	int ret = 1e9;
	for(int i=0; i<100000; i++){
		if(!dp1[i]) continue;
		int reqCnt = 0;
		if(i < n * k){
			reqCnt = (n * k - i + n - 1) / n;
		}
		for(int j = max(0, acc - i); j < 100000; j++){
			if(dp2[j] >= reqCnt){
				ret = min(ret, j + i);
			}
		}
	}
	if(ret > 1e8) puts("Impossible");
	else cout << ret - acc << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 20 ms 1144 KB Output is correct
13 Correct 230 ms 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 1144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1144 KB Output is correct
2 Correct 27 ms 1144 KB Output is correct
3 Correct 93 ms 1144 KB Output is correct
4 Correct 87 ms 1144 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 20 ms 1144 KB Output is correct
13 Correct 230 ms 1184 KB Output is correct
14 Execution timed out 1071 ms 1144 KB Time limit exceeded
15 Halted 0 ms 0 KB -