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];
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;
}
int ans = 1LL << 60;
for(int mask = 0; mask < (1 << m); mask++){
int s = 0, c = 0;
for(int j = 0; j < m; j++){
if(mask & (1 << j)) s += b[j], c += min(b[j], n);
}
if(s >= s_a && c >= k * n){
ans = min(ans, s - s_a);
}
}
assert(ans != (1LL << 60));
cout << 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... |