#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e17;
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k;
vector<int> a, b;
cin >> n >> m >> k;
a.resize(n);
for(auto &e : a) cin >> e;
b.resize(m);
for(auto &e : b) cin >> e;
vector<int> B = b;
if(a[0] < k){
cout << "Impossible";
return 0;
}
int ans = mod;
for(int all = 0; all < (1<<m); all++){
if(__builtin_popcount(all) < k) continue;
int s = 0;
b = B;
for(auto x : a){
int K = 0;
for(int i = 0;i < m; i++){
if(all & (1<<i) && b[i] > 0 && K < k){
b[i]--, K++, x--;
}
}
if(K != k){
s = mod;
break;
}
for(int i = 0;i < m; i++){
if(all & (1<<i) && x > 0){
if(b[i] >= x){
b[i]-= x;
x = 0;
}else{
x-= b[i];
b[i] = 0;
}
}
}
if(x != 0){
s = mod;
break;
}
}
for(int i = 0;i < m; i++){
if(all & (1<<i)){
s+= b[i];
}
}
ans = min(ans, s);
}
if(ans >= mod){
cout << "Impossible";
return 0;
}
cout << ans;
return 0;
}
Compilation message
kitchen.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
2 ms |
456 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
2 ms |
456 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |