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;
const int MXN = 305;
int n, m, k;
int dp[2*MXN*MXN];
int A[MXN], B[MXN];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for(int i = 0; i < n; i++) cin >> A[i];
for(int i = 0; i < m; i++) cin >> B[i];
for(int i = 0; i < n; i++) {
if(A[i] < k) {
cout << "Impossible\n";
return 0;
}
}
int sum = accumulate(A, A+n, 0);
fill(dp, dp+2*MXN*MXN, -1e9);
dp[0] = 0;
for(int i = 0; i < m; i++) {
for(int j = 2*MXN*MXN-1; j >= B[i]; j--) {
dp[j] = max(dp[j], dp[j-B[i]]+min(B[i], n));
}
}
for(int i = sum; i < 2*MXN*MXN; i++) {
if(dp[i] >= n*k) {
cout << i-sum << "\n";
return 0;
}
}
cout << "Impossible\n";
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... |