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;
#define FOR(i, x, y) for (int i = x; i < y; i++)
int n, m, k, sm, bad = 0, ans = 1e9, A[305], B[305], dp[305][100005];
int main(){
cin >> n >> m >> k;
FOR(i, 1, n + 1) cin >> A[i], sm += A[i], bad |= (A[i] < k);
FOR(i, 1, m + 1) cin >> B[i];
memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0;
FOR(i, 1, m + 1) FOR(j, 0, 100005){
dp[i][j] = dp[i - 1][j];
if (j - B[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - B[i]] + min(B[i], n));
if (j >= sm and dp[i][j] >= n * k) ans = min(ans, j - sm);
}
cout<<((bad or ans == 1e9) ? "Impossible" : to_string(ans))<<endl;
}
# | 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... |