#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
const int MAXN = 302;
const int SM = MAXN * 300;
int a[MAXN];
int b[MAXN];
bitset<SM> dps;
bitset<SM> dpb[MAXN];
signed main() {
int n, m, k;
cin >> n >> m >> k;
int needsm = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
needsm += a[i];
if (a[i] < k) {
cout << "Impossible\n";
return 0;
}
}
for (int i = 0; i < m; ++i)
cin >> b[i];
sort(b, b + m);
int bord = lower_bound(b, b + m, n) - b;
dps[0] = 1;
for (int i = 0; i < bord; ++i) {
dps = dps | (dps << b[i]);
}
dpb[0][0] = 1;
for (int i = bord; i < m; ++i) {
for (int cnt = m; cnt > 0; --cnt) {
dpb[cnt] |= dpb[cnt - 1] << b[i];
}
}
vector<int> sms_arr;
for (int sms = 0; sms < SM; sms = dps._Find_next(sms))
sms_arr.push_back(sms);
sms_arr.push_back(SM);
int ans = SM;
for (int cnt = 0; cnt <= m; ++cnt) {
int is = sms_arr.size() - 1;
for (int smb = 0; smb < SM; smb = dpb[cnt]._Find_next(smb)) {
while (is > 0 && (sms_arr[is - 1] + smb >= needsm && sms_arr[is - 1] >= n * (k - cnt)))
--is;
//cout << "(" << cnt << ' ' << smb << "): " << sms_arr[is] << endl;
ans = min(ans, sms_arr[is] + smb);
}
}
if (ans < SM) {
cout << ans - needsm << '\n';
} else {
cout << "Impossible\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
448 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
708 KB |
Output is correct |
3 |
Correct |
11 ms |
4052 KB |
Output is correct |
4 |
Correct |
99 ms |
4028 KB |
Output is correct |
5 |
Correct |
30 ms |
4168 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
708 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
448 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
708 KB |
Output is correct |
16 |
Correct |
11 ms |
4052 KB |
Output is correct |
17 |
Correct |
99 ms |
4028 KB |
Output is correct |
18 |
Correct |
30 ms |
4168 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
708 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
128 ms |
2644 KB |
Output is correct |
26 |
Correct |
164 ms |
3032 KB |
Output is correct |
27 |
Correct |
43 ms |
2108 KB |
Output is correct |
28 |
Correct |
95 ms |
3152 KB |
Output is correct |
29 |
Correct |
172 ms |
3088 KB |
Output is correct |
30 |
Correct |
130 ms |
4028 KB |
Output is correct |