#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll cost = 0;
ll n, m, k;
vector<ll> meals, possible_chefs;
bool possible(vector<ll> chefs) {
for (ll i = 0; i < n; i++) {
sort(chefs.rbegin(), chefs.rend());
if (meals[i] < k)
return false;
for (ll j = 0; j < k; j++) {
if (chefs[j] == 0)
return false;
chefs[j]--;
}
}
return true;
}
int main() {
cin >> n >> m >> k;
meals.resize(n);
for (ll i = 0; i < n; i++) {
cin >> meals[i];
cost += meals[i];
}
possible_chefs.resize(m);
for (ll i = 0; i < m; i++)
cin >> possible_chefs[i];
ll ans = 1e15;
for (ll mask = 0; mask <= (1 << m); mask++) {
if (__builtin_popcount(mask) < k)
continue;
vector<ll> chefs;
ll sum = 0;
for (ll i = 0; i < m; i++)
if (1 & (mask >> i)) {
chefs.push_back(possible_chefs[i]);
sum += possible_chefs[i];
}
if (cost <= sum && possible(chefs))
ans = min(ans, sum - cost);
}
if (ans == 1e15)
cout << "impossible" << endl;
else
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |