#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using ll = long long;
#define debug(x) #x << " = " << x << '\n'
const int MAX = 300;
const int INF = 1e9;
int dp[MAX * MAX + 1];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, m, k;
std::cin >> n >> m >> k;
int sumA = 0;
for (int i = 0; i < n; i++) {
int x;
std::cin >> x;
if (x < k) {
std::cout << "Impossible";
return 0;
}
sumA += x;
}
dp[0] = 0;
for (int s = 1; s <= MAX * MAX; s++) {
dp[s] = -INF;
}
int sum = 0;
for (int i = 0; i < m; i++) {
int x;
std::cin >> x;
sum += x;
for (int s = sum; s >= x; s--) {
dp[s] = std::max(dp[s], dp[s - x] + std::min(n, x));
}
}
int answer = -1;
for (int s = sumA; s <= sum; s++) {
if (dp[s] >= n * k) {
answer = s;
break;
}
}
if (answer == -1) {
std::cout << "Impossible";
} else {
answer -= sumA;
std::cout << answer;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |