#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;
int ketto[20];
ketto[0] = 1;
for(int i = 1; i < 20; i++){
ketto[i] = 2 * ketto[i - 1];
}
for(int i = 0; i < ketto[m]; i++){
int sum = 0;
for(int j = 0; j < m; j++){
if(ketto[j] & i){
sum += b[j];
}
}
if(csum > sum){
continue;
}
priority_queue<int> pq;
for(int j = 0; j < m; j++){
pq.push(b[j]);
}
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);
pq.pop();
}
else{
errar = true;
}
}
for(int e : vf){
if(e > 0){
pq.push(e);
}
}
}
if(!errar){
ans = min(ans, sum - csum);
continue;
}
}
if(ans != INT_MAX)
cout << ans << endl;
else cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |