# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1004572 | HasanV11010238 | Kitchen (BOI19_kitchen) | C++17 | 11 ms | 432 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 ll long long
#define INF 1000000000
int main(){
ll n, m, k, su = 0, bsu = 0;
cin>>n>>m>>k;
bool ca = 0;
if (m < k){
ca = 1;
}
vector<ll> a(n + 1), b(m + 1);
for (int i = 0; i< n; i++){
cin>>a[i];
su += a[i];
if (a[i] < k){
ca = 1;
}
}
for (int i = 0; i < m; i++){
cin>>b[i];
bsu += b[i];
}
if (ca || bsu < su){
cout<<"Impossible";
return 0;
}
ll ans = INF;
int ti = (1<<m);
for (int i = 0; i < ti; i++){
ll msu = 0;
vector<int> ti(n, k), mval;
for (int j = 0; j < m; j++){
int val = i & (1<<j);
if (val != 0){
msu += b[j];
mval.push_back(b[j]);
}
}
int le = n;
for (int j = 0; j < n; j++){
for (int k = 0; k < mval.size(); k++){
if (mval[k] != 0 && ti[j] != 0){
mval[k]--;
ti[j]--;
if (ti[j] == 0){
le--;
}
}
}
}
if (le == 0){
if (msu >= su){
ans = min(ans, msu - su);
}
}
}
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... |