This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if (m < k) return cout << "Impossible\n", 0;
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";
}
# | 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... |