#include <bits/stdc++.h>
using namespace std;
int n, m, k, dp[(300 * 303)], a[300], b[300], sum = 0;
int gt[(300*303)];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
int mn = 1e9;
for (int i = 0; i < n; i++) {
cin >> a[i];
gt[a[i]]++;
sum += a[i];
mn = min(mn, a[i]);
}
if (mn < k) {
cout << "Impossible";
return 0;
}
for (int i = 300*301; i >= 0; i--) {
gt[i] += gt[i+1];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
for (int j = 300*301; j >= b[i]; j--) {
dp[j] = max(dp[j], min(b[i], gt[dp[j-b[i]]+1]) + dp[j-b[i]]);
}
}
for (int i = sum; i <= 300 * 301 ; i++) {
if (dp[i] >= n * k) {
cout << i - sum;
return 0;
}
}
cout << "Impossible";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
1172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |