#include <bits/stdc++.h>
using namespace std;
void impossible(){ cout << "Impossible"; exit(0); }
const int MAXN = 90005;
bitset<MAXN> dpSmall;
bitset<MAXN> dpBig[305];
vector<int> small, big, smallCan;
int main(){
int n, m, K; cin >> n >> m >> K;
int sumA = 0;
for(int i = 0;i < n;i++){
int a; cin >> a;
sumA += a;
if(a < K) impossible();
}
for(int i = 0;i < m;i++){
int b; cin >> b;
if(b < K) small.push_back(b);
else big.push_back(b);
}
dpSmall[0] = 1;
for(int b : small) dpSmall |= (dpSmall << b);
for(int i = 0;i <= MAXN;i++){
if(dpSmall[i]) smallCan.push_back(i);
}
dpBig[0][0] = 1;
for(int b : big){
for(int i = (int) big.size();i >= 1;i--){
dpBig[i] |= (dpBig[i-1] << b);
}
}
int ans = 102345678;
for(int no = 0;no <= m;no++){
for(int total = 0;total <= MAXN;total++){
if(dpBig[no][total]){
int need = max(sumA - total, (K-no)*n);
auto it = lower_bound(smallCan.begin(),smallCan.end(), need);
if(it == smallCan.end()) continue;
ans = min(ans, *it + total);
}
}
}
if(ans == 102345678) impossible();
cout << ans - sumA;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
282 ms |
3320 KB |
Output is correct |
2 |
Correct |
212 ms |
2936 KB |
Output is correct |
3 |
Correct |
372 ms |
3704 KB |
Output is correct |
4 |
Correct |
353 ms |
3744 KB |
Output is correct |
5 |
Correct |
339 ms |
3704 KB |
Output is correct |
6 |
Correct |
179 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
768 KB |
Output is correct |
2 |
Incorrect |
9 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
7 ms |
512 KB |
Output is correct |
14 |
Correct |
282 ms |
3320 KB |
Output is correct |
15 |
Correct |
212 ms |
2936 KB |
Output is correct |
16 |
Correct |
372 ms |
3704 KB |
Output is correct |
17 |
Correct |
353 ms |
3744 KB |
Output is correct |
18 |
Correct |
339 ms |
3704 KB |
Output is correct |
19 |
Correct |
179 ms |
2808 KB |
Output is correct |
20 |
Correct |
13 ms |
768 KB |
Output is correct |
21 |
Incorrect |
9 ms |
512 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |