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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
vector<int> A(n), B(m);
int s1 = 0, s2 = 0;
for(int &x: A){
cin >> x, s1+=x;
if(x < k){
cout << "Impossible\n";
exit(0);
}
}
for(int &x: B) cin >> x, s2+=x;
vector<vector<int>> dp(m, vector<int>(s2+1, 0));
for(int i = m-1; i >= 0; i--) for(int j = s2; j >= 0; j--){
if(j-B[i] >= 0){
dp[i][j] = max(dp[i][j], (i != m-1 ? dp[i+1][j-B[i]]:0)+min(B[i], n));
}
}
for(int i = s1; i <= s2; i++){
if(dp[0][i] >= n*k){
cout << i-s1 << "\n";
exit(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... |