#include "bits/stdc++.h"
using namespace std;
#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif
const int maxn = 305;
const int N = 9e4 + 6;
int n, m, k, a[maxn], b[maxn];
int f[maxn][N];
int prf[maxn];
void solve() {
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
cin >> b[i];
prf[i] = prf[i - 1] + b[i];
}
sort(b + 1, b + m + 1);
int rm = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < k) {
cout << "impossible";
return;
}
rm += a[i];
}
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < N; ++j) {
f[i][j] = f[i - 1][j];
}
for (int j = b[i]; j < N; ++j) {
f[i][j] = max(f[i][j], f[i - 1][j - b[i]] + min(n, b[i]));
}
}
for (int i = rm; i < N; ++i) {
if (f[m][i] >= n * k) {
cout << i - rm;
return;
}
}
cout << "impossible";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
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... |