Submission #925734

# Submission time Handle Problem Language Result Execution time Memory
925734 2024-02-12T07:59:27 Z vjudge1 Kitchen (BOI19_kitchen) C++17
29 / 100
20 ms 5280 KB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" 	
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ld eps = 1e-6;

ll add (ll a, ll b) {
	a += b;
	if (a < 0) a += mod;
	if (a >= mod) a -= mod;
	return a;
}

ll mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int n, m, k, a[N], b[N], dp[N];

void solve () {
	cin >> n >> m >> k;
	int sum = 0;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	if (k == 1) {
		dp[0] = 1;
		for (int i = 1; i <= m; i++) {
			for (int w = 90000 - b[i]; w >= 0; w--) dp[w + b[i]] |= dp[w];
		}
		for (int i = sum; i <= 90000; i++) {
			if (dp[i]) cout << i - sum << '\n', exit(0);
		}
		cout << "Impossible\n";
		return;
	}
	int ans = inf;
	for (int mask = 0; mask < (1 << m); mask++) {
		int res = 0;
		priority_queue<int> q;
		for (int i = 0; i < m; i++) {
			if (bit(mask, i)) q.push(b[i + 1]), res += b[i + 1];
		}
		if (sz(q) < k) continue;
		bool ok = 1;
		for (int j = 1; j <= n && ok; j++) {
			if (a[j] < k) ok = 0;
			int kol = 0;
			while (!q.empty()) {
				int x = q.top();
				q.pop();
				if (x == 0) {
					ok = 0;
					break;
				}
				x--, kol++;
				q.push(x);
				if (kol == k) break;
			}
			if (kol != k) ok = 0;
		}
		res -= sum;
		if (ok && res >= 0) ans = min(ans, res);
	}
	if (k > m || ans == inf) cout << "Impossible\n", exit(0);
	cout << ans;
	cout << '\n';
}

bool testcases = 0;

signed main() {
#ifdef AMIR
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	cin.tie(0) -> sync_with_stdio(0);
	int test = 1;
	if (testcases) cin >> test;
	for (int cs = 1; cs <= test; cs++) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 10 ms 4444 KB Output is correct
10 Correct 12 ms 4440 KB Output is correct
11 Incorrect 7 ms 4444 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5280 KB Output is correct
2 Correct 16 ms 5212 KB Output is correct
3 Correct 20 ms 5280 KB Output is correct
4 Correct 20 ms 5212 KB Output is correct
5 Correct 20 ms 5208 KB Output is correct
6 Correct 14 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 10 ms 4444 KB Output is correct
10 Correct 12 ms 4440 KB Output is correct
11 Incorrect 7 ms 4444 KB Output isn't correct
12 Halted 0 ms 0 KB -