#include <bits/stdc++.h>
#define ALL(X) begin(X), end(X)
using namespace std;
using i64 = long long;
template <class T>
using vec = vector<T>;
template <class T>
istream& operator>>(istream& is, vec<T>& V) {
for (auto& x : V) is >> x;
return is;
}
constexpr int inf = 1'000'000'000;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k; cin >> n >> m >> k;
int sum_a{};
for (int i = 0; i < n; i++) {
int x; cin >> x;
if (x < k) return cout << "Impossible\n", 0;
sum_a += x;
}
vec<int> b(m);
cin >> b;
int sum_b = reduce(ALL(b));
vec<int> dp(sum_b + 1, -inf);
dp[sum_b] = 0;
for (auto x : b) {
for (int w = 0; w + x <= sum_b; w++)
dp[w] = max(dp[w], dp[w + x] + min(x, n));
}
for (int i = sum_a; i <= sum_b; i++)
if (dp[sum_b - i] >= n * k)
return cout << sum_b - sum_a << '\n', 0;
cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |