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;
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 < n; i ++) {
if(meal[i] < k) {
cout << "Impossible";
return 0;
}
}
if(m < k) {
cout << "Impossible\n";
return 0;
}
for(int i = 0; i < m; i ++) cin >> chef[i];
for(int i = 0; i < n; i ++) mealCopy[i] = meal[i];
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]-1);
}
for(int i = 0; i < n; i ++) meal[i] -= k;
int res = 0, cur = 0;
for(int i = 0; i < n; i ++) {
if(meal[i] == 0) continue;
if(cur == cook.size()) {
cout << "Impossible\n";
goto end;
}
if(cook[cur] > meal[i]) {
cook[cur] -= meal[i];
meal[i] = 0;
}else {
meal[i] -= cook[cur];
cook[cur]=0;
cur ++, i --;
}
}
res = accumulate(cook.begin(), cook.end(), 0);
ans = min(ans, res);
end:;
for(int i = 0; i < n; i ++) meal[i] = mealCopy[i];
}
if(ans == 1e9) cout << "Impossible";
else cout << ans;
return 0;
}
Compilation message (stderr)
kitchen.cpp: In function 'int main()':
kitchen.cpp:34:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(cur == cook.size()) {
| ~~~~^~~~~~~~~~~~~~
# | 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... |