Submission #124870

# Submission time Handle Problem Language Result Execution time Memory
124870 2019-07-04T04:57:36 Z 구재현(#3056) Kitchen (BOI19_kitchen) C++14
21 / 100
1000 ms 1272 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 + 99999 + 1, -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;
		}
		int reqSum = acc - i;
		for(int j = reqSum; 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 632 KB Output is correct
5 Incorrect 3 ms 1144 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 632 KB Output is correct
5 Incorrect 3 ms 1144 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 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 92 ms 1144 KB Output is correct
4 Correct 87 ms 1272 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 632 KB Output is correct
5 Incorrect 3 ms 1144 KB Output isn't correct
6 Halted 0 ms 0 KB -