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>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N), B(M);
for (auto &i : A) cin >> i;
for (auto &i : B) cin >> i;
int s = 0;
for (int i = 0; i < N; i++) {
if (A[i] < K) {
cout << "Impossible";
return 0;
}
s += A[i];
}
vector dp(M + 1, vector<int>(90001, -1e9));
dp[0][0] = 0;
for (int i = 0; i < M; i++) {
dp[i + 1] = dp[i];
for (int j = B[i]; j <= 90000; j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - B[i]] + min(B[i], N));
}
}
for (int i = s; i <= 90000; i++) {
if (dp[M][i] >= N * K) {
cout << i - s;
return 0;
}
}
cout << "Impossible";
return 6/22;
}
# | 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... |