This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismi Allah
#include "bits/stdc++.h"
using namespace std;
#define int long long
signed main () {
int n, m, k;
cin >> n >> m >> k;
int meal[n], chef[m], mealCopy[n];
for(int i = 0; i < n; i ++) cin >> meal[i];
for(int i = 0; i < m; i ++) cin >> chef[i];
if(*min_element(meal, meal + n) < k) {
cout << "Impossible";
return 0;
}
if(m < k) {
cout << "Impossible";
return 0;
}
int ans = 1e9;
for(int mask = 0; mask < (1 << m); mask ++) {
if(__builtin_popcount(mask) < k) continue;
vector <int> cook;
for(int i = 0; i < m; i ++) {
if(mask & (1 << i)) {
cook.push_back(chef[i]);
}
}
if(accumulate(cook.begin(), cook.end(), 0LL) < accumulate(meal, meal + n, 0LL)) continue;
ans = min(ans, accumulate(cook.begin(), cook.end(), 0LL) - accumulate(meal, meal + n, 0LL));
}
if(ans == 1e9) cout << "Impossible";
else
cout << ans;
return 0;
}
Compilation message (stderr)
kitchen.cpp: In function 'int main()':
kitchen.cpp:11:24: warning: unused variable 'mealCopy' [-Wunused-variable]
11 | int meal[n], chef[m], mealCopy[n];
| ^~~~~~~~
# | 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... |