#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
const int N = (int)4e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7;
int mult(int x, int y) {
return 1ll*x*y%MOD;
}
int sum(int x, int y) {
x += y;
if(x >= MOD) {
x -= MOD;
}
return x;
}
int sub(int x, int y) {
x -= y;
if(x < 0) {
x += MOD;
}
return x;
}
int n, m, k;
int a[301], b[301];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n >> m >> k;
int tot = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
tot += a[i];
}
for(int i = 1; i <= m; ++i) {
cin >> b[i];
}
if(m<k) {
cout << "Impossible\n";
return 0;
}
sort(a+1, a+1+n);
sort(b+1, b+1+m);
int ans = inf;
for(int mask = 1; mask < (1 << m); ++mask) {
vector<int> c;
for(int i = 0; i < m; ++i) {
if(mask >> i & 1) {
c.push_back(b[i+1]);
}
}
if((int)c.size() < k) {
continue;
}
bool ok = 1;
for(int i = 1; i <= n && ok; ++i) {
sort(c.rbegin(), c.rend());
if(a[i] < k) {
ok = 0;
}
for(int j = 0; j < a[i] && ok; ++j) {
if(c[j] == 0) {
ok = 0;
} else {
c[j]--;
}
}
if(a[i] > 0) {
ok = 0;
}
}
if(ok) {
int cur = 0;
for(int i = 0; i < m; ++i) {
if(mask >> i & 1) {
cur += b[i+1];
}
}
ans = min(ans, cur-tot);
}
}
if(ans == inf) {
cout << "Impossible\n";
return 0;
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |