# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921092 | shoryu386 | Kitchen (BOI19_kitchen) | C++17 | 8 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, k; cin >> n >> m >> k;
int buckets[n], balls[m];
for (int x = 0; x < n; x++) cin >> buckets[x];
for (int x = 0; x < m; x++) cin >> balls[x];
#define IMP cout << "Impossible"; return 0;
bool dead = false;
for (int x = 0; x < n; x++){
if (buckets[x] < k){
dead = true;
}
}
if (dead) {IMP;}
if (m <= 15){
int ans = LLONG_MAX/20;
int bucketSum = 0;
for (int x = 0; x < n; x++) bucketSum += buckets[x];
for (int bm = 0; bm < (1LL<<m); bm++){
if (__builtin_popcountll(bm) < k){
continue;
}
vector<int> chefs;
for (int x = 0; x < m; x++){
if (bm & (1<<x)){
chefs.push_back(balls[x]);
}
}
int chefsum = 0;
for (int x = 0; x < chefs.size(); x++) chefsum += chefs[x];
int needsum = n*k;
for (int x = 0; x < chefs.size(); x++){
needsum -= min(chefs[x], n);
}
bool works = true;
if (needsum > 0){
works = false;
}
if (works && chefsum >= bucketSum){
ans = min(ans, chefsum - bucketSum);
}
}
if (ans == LLONG_MAX/20) {IMP;}
else cout << ans;
}
else if (k == 1){
//subtask 3
#define BSMAX 100000
//300^2
bitset<BSMAX> bs;
bs[0] = 1;
for (int x = 0; x < m; x++){
bs |= (bs << balls[x]);
}
int bucketsum = 0;
for (int x = 0; x < n; x++){
bucketsum += buckets[x];
}
int ans = -1;
for (int x = bucketsum; x < BSMAX; x++){
if (bs[x]){
ans = x-bucketsum;
break;
}
}
if (ans == -1) cout << "Impossible";
else cout << ans;
}
}
Compilation message (stderr)
# | 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... |