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;}
int bucketsum = 0;
for (int x = 0; x < n; x++){
bucketsum += buckets[x];
}
#define BSMAX 1607
bool hmm[m+1][BSMAX][n*k+1];
memset(hmm, 0, sizeof(hmm));
hmm[0][0][n*k] = 1;
for (int x = 0; x < m; x++){
for (int y = 0; y < BSMAX; y++){
for (int z = 0; z <= n*k; z++){
if (!hmm[x][y][z]) continue;
hmm[x+1][y + balls[x]][max(0LL, z - min(balls[x], n))] = 1;
hmm[x+1][y][z] = 1;
}
}
}
int ans = -1;
for (int x = bucketsum; x < BSMAX; x++){
if (hmm[m][x][0]){
ans = x-bucketsum;
break;
}
}
if (ans == -1) cout << "Impossible";
else cout << ans;
}
Compilation message (stderr)
kitchen.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# | 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... |