Submission #926095

# Submission time Handle Problem Language Result Execution time Memory
926095 2024-02-12T14:48:35 Z vjudge1 Kitchen (BOI19_kitchen) C++17
51 / 100
8 ms 488 KB
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<iomanip>
#include<bitset>

using namespace std;

const int N = (int)4e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7; 

int mult(int x, int y) {
	return 1ll*x*y%MOD;
}

int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}

int sub(int x, int y) {
	x -= y;
	if(x < 0) {
		x += MOD;
	}
	return x;
}

int n, m, k, old[301];
int a[301], b[301];

int main() {	
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cin >> n >> m >> k;
	int tot = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		old[i] = a[i];
		tot += a[i];
	}
	for(int i = 1; i <= m; ++i) {
		cin >> b[i];
	}
	bitset<90005> dp;
	dp[0] = 1;
	for(int i = 1; i <= m; ++i) {
		dp |= (dp << b[i]);	
	}
	if(m<k) {
		cout << "Impossible\n";
		return 0;
	}
	for(int i = 1; i <= n; ++i) {
		if(a[i]<k) {
			cout << "Impossible\n";
			return 0;
		}
	}
	if(k == 1) {
		for(int s = tot; s <= 90000; ++s) {
			if(dp[s]) {
				cout << s-tot << "\n";
				return 0;
			}
		}
		cout << "Impossible";
		return 0;
	}
	sort(b+1, b+1+m);
	int ans = inf;
	for(int mask = 1; mask < (1 << m); ++mask) {
		vector<int> c;
		for(int i = 0; i < m; ++i) {
			if(mask >> i & 1) {
				c.push_back(b[i+1]);
			}
		}	
		if((int)c.size() < k) {
			continue;
		}
		int ruc = 0;
		for(auto x : c) {
			ruc += min(x, n);
		}
		if(ruc >= n*k) {
			int oto = 0;
			for(auto x : c) {
				oto += x;
			}
			for(int i = 1; i <= n; ++i) {
				oto -= a[i];
			}
			if(oto < 0) {
				continue;
			}
			int cur = 0;
			for(int i = 0; i < m; ++i) {
				if(mask >> i & 1) {
					cur += b[i+1];
				}
			}
			ans = min(ans, cur-tot);
		}
	}
	if(ans == inf) {
		cout << "Impossible\n";
		return 0;
	}
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 7 ms 352 KB Output is correct
11 Correct 6 ms 352 KB Output is correct
12 Correct 6 ms 488 KB Output is correct
13 Correct 8 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 7 ms 352 KB Output is correct
11 Correct 6 ms 352 KB Output is correct
12 Correct 6 ms 488 KB Output is correct
13 Correct 8 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Incorrect 1 ms 352 KB Output isn't correct
21 Halted 0 ms 0 KB -