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
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int n, m, k;
vector<int> a, b;
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
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;
sort(all(a));
int ans = INT_MAX;
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 = INT_MAX;
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 = INT_MAX;
break;
}
}
for(int i = 0;i < m; i++){
if(all & (1<<i)){
s+= b[i];
}
}
ans = min(ans, s);
}
if(ans >= INT_MAX){
cout << "impossible";
return 0;
}
cout << ans;
return 0;
}
Compilation message (stderr)
kitchen.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | 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... |