#include <bits/stdc++.h>
using i64 = long long;
void chmax(int &a, int b) {
if (a < b)
a = b;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, k;
std::cin >> n >> m >> k;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
if (a[i] < k) {
std::cout << "Impossible\n";
return 0;
}
}
std::vector<int> b(m);
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
int sum = std::accumulate(a.begin(), a.end(), 0);
int N = std::accumulate(b.begin(), b.end(), 0);
std::vector<int> dp(N + 1, 0);
for (int i = 0; i < m; i++) {
for (int j = N - b[i]; j >= 0; j--) {
chmax(dp[j + b[i]], dp[j] + std::min(n, b[i]));
}
}
int ans = 1E9;
for (int i = sum; i <= N; i++) {
if (dp[i] >= n * k) {
ans = std::min(ans, i - sum);
}
}
if (ans == 1E9) {
std::cout << "Impossible\n";
} else {
std::cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |