#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (a[i] < k) {
cout << "Impossible";
return 0;
}
}
for (int i = 0; i < m; i++) cin >> b[i];
int limit = *max_element(a.begin(), a.end());
vector<int> aa(limit);
for (int i = 0; i < limit; i++) {
for (int j = 0; j < n; j++) {
aa[i] += a[j] > i;
}
}
sort(b.begin(), b.end(), greater<int>());
int sum = accumulate(b.begin(), b.end(), 0);
vector<pair<int, int>> f(sum + 1, make_pair(-1, -1));
f[0] = make_pair(0, 0);
int s = 0;
auto get = [&](pair<int, int> a, int b) {
if (a.first == limit) return make_pair(limit, 0);
assert(a.second != aa[a.first]);
int x = a.second;
a.second += b;
if (a.second >= aa[a.first]) {
a.second %= aa[a.first];
a.first++;
a.second = a.first == limit ? 0 : min(aa[a.first], min(a.second, x));
}
return a;
};
for (int i = 0; i < m; i++) {
for (int j = s; j >= 0; j--) {
if (f[j].first == -1) continue;
f[j + b[i]] = max(f[j + b[i]], get(f[j], b[i]));
}
s += b[i];
}
for (int i = accumulate(a.begin(),a.end(),0); i <= sum; i++) {
if (f[i].first >= k) {
cout << i - accumulate(a.begin(), a.end(), 0);
return 0;
}
}
cout << "Impossible";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
3 |
Runtime error |
3 ms |
1368 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |