#include <bits/stdc++.h>
using namespace std;
int main(){
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
int csum = 0, mmm = k;
for(int i = 0; i < n; i++){
cin >> a[i];
csum += a[i];
mmm = min(mmm, a[i]);
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
if(mmm < k){
cout << "Impossible\n";
return 0;
}
int ans = INT_MAX;
//2 ad n részhalmazon megyűnk végig
for(int i = 0; i < (1 << m); i++){
int sum = 0;
for(int j = 0; j < m; j++){
if((1 << j) & i){
sum += b[j];
}
}
if(csum > sum){
continue;
}
priority_queue<int> pq;
for(int i = 0; i < m; i++){
pq.push(b[i]);
}
int n1 = n;
vector<int> vf;
int errar = false;
while(n1--){
int k1 = k;
vf.clear();
while(k1--){
if(pq.size() > 0 && pq.top() > 0){
vf.push_back(pq.top() - 1);
}
else{
errar = true;
}
pq.pop();
}
for(int e : vf){
if(e > 0){
pq.push(e);
}
}
}
if(!errar){
ans = min(ans, sum);
}
}
if(ans != INT_MAX)
cout << ans << endl;
else cout << "Impossible\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |