/*
cf : F112
/) /) ~ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃
( •-• ) ~ ♡ You are amazing ♡
/ づづ ~ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long
#define Ali ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 1e5 + 7;
const int P = 233;
const int len = 250;
const int MOD = 1e9 + 7;
const int inf = 1e18;
int gcd(int x, int y){
while(y){
x %= y;
swap(x, y);
}
return x;
}
int binpow(int n, int k){
if (k == 0) return 1;
if (k % 2 == 0){
int val = binpow(n, k / 2);
return (val * val) % MOD;
}
return (n * binpow(n, k - 1)) % MOD;
}
void abb() {
int n, m, k;
cin >> n >> m >> k;
vector < int > a(n + 1);
vector < int > b(m + 1);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) cin >> b[i];
if (k > m){
cout << "Impossible\n";
return;
}
int best = inf;
for (int mask = 1; mask < (1 << m); ++mask){
if (__builtin_popcount(mask) < k){
continue;
}
vector < int > chosen; int sum = 0;
for (int i = 0; i < m; ++i){
if (mask >> i & 1) chosen.push_back(i + 1), sum += b[i + 1];
}
bool ok = true;
for (int i = 1; i <= n; ++i){
ok &= (a[i] >= k && a[i] <= sum);
}
if (ok == true){
for (int i = 1; i <= n; ++i) sum -= a[i];
if (sum < best){
best = sum;
}
}
}
if (best == inf) {
cout << "Impossible\n";
return;
}
cout << best << "\n";
}
signed main(){
Ali;
int T = 1;
// cin >> T;
while(T--){
abb();
}
}
| # | 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... |