Submission #1135022

#TimeUsernameProblemLanguageResultExecution timeMemory
1135022lucaskojimaKitchen (BOI19_kitchen)C++17
0 / 100
38 ms328 KiB
// subtask 3
#include "bits/stdc++.h"
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

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

const char nl = '\n';
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);

	int n, m, k; cin >> n >> m >> k; // k = 1
	vector<int> a(n); for (auto &x : a) cin >> x;
	vector<int> b(m); for (auto &x : b) cin >> x;

	int sumA = accumulate(all(a), 0);
	int sumB = accumulate(all(b), 0);

	vector<bool> dp(sumB + 1);
	dp[0] = 1;

	for (int val = 1; val <= sumB; val++)
		for (int i = 0; i < m; i++) {
			if (val - b[i] < 0) continue;
			dp[val] = (dp[val] || dp[val - b[i]]);
		}

	int ans = INF;
	for (int val = sumA; val <= sumB; val++)
		if (dp[val]) ans = min(ans, val - sumA);

	if (ans == INF)
		cout << "Impossible" << nl;
	else
		cout << ans << nl;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...