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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M, K, S, A[1 << 18], B[1 << 18];
int dp[309][90009];
int solve_subtask5() {
for (int i = 0; i <= M; i++) {
for (int j = 0; j <= 90000; j++) dp[i][j] = -(1 << 30);
}
dp[0][0] = 0;
for (int i = 0; i < M; i++) {
for (int j = 0; j <= 90000; j++) {
if (dp[i][j] == -(1 << 30)) continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + B[i]] = max(dp[i + 1][j + B[i]], dp[i][j] + min(B[i], N));
}
}
for (int i = S; i <= 90000; i++) {
if (dp[M][i] >= N * K) return i - S;
}
return (1 << 30);
}
int main() {
cin >> N >> M >> K;
for (int i = 0; i < N; i++) {
cin >> A[i]; S += A[i];
if (A[i] < K) {
cout << "Impossible" << endl;
return 0;
}
}
for (int i = 0; i < M; i++) cin >> B[i];
int ans = solve_subtask5();
if (ans == (1 << 30)) cout << "Impossible" << endl;
else cout << ans << endl;
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... |