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 int long long
using namespace std;
const int MAXN = 300 + 11;
int a[MAXN], b[MAXN];
int dp[MAXN * MAXN]; // for fixed sum, maximise count
int32_t main(){
int n, m, k; cin >> n >> m >> k;
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = 0; j < m; j++) cin >> b[j];
for(int i = 0; i < n; i++){
if(a[i] < k){
cout << "Impossible" << endl;
return 0;
}
}
int s_a = accumulate(a, a + n, 0LL);
int s_b = 0, c_b = 0;
for(int j = 0; j < m; j++) s_b += b[j], c_b += min(b[j], n);
if(s_a > s_b || n * k > c_b){
cout << "Impossible" << endl;
return 0;
}
fill(dp + 1, dp + MAXN * MAXN, -(1LL << 60));
for(int j = 0; j < m; j++){
for(int i = MAXN * MAXN - 1 - b[j]; i >= 0; i--){
dp[i + b[j]] = max(dp[i + b[j]], dp[i] + min(b[j], n));
}
}
for(int i = s_a;; i++){
if(dp[i] >= k * n){
cout << i - s_a << 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... |