#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10000 + 3;
void fun () {
int n, k, m;
cin >> n >> m >> k;
vector<int> a(n + 1), 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";
return;
}
vector<int> dp(N);
dp[0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = N - 1; j >= b[i]; j--) {
dp[j] |= dp[j - b[i]];
}
}
int s = 0;
for (int i = 1; i <= n; i++) {
s += a[i];
}
for (int i = s; i < N; i++) {
if (dp[i]) {
cout << i - s << endl;
return;
}
}
}
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) fun();
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... |