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 f first
#define s second
using namespace std;
const int N = 310;
int n, m, k, a[N], b[N];
pair<int, int> dp[N * N], ndp[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m >> k;
for (int i = 1;i <= n;i++)
cin >> a[i];
int sum = 0;
sort(a + 1, a + n + 1);
for (int i = 1;i <= n;i++)
sum += a[i];
for (int i = 1;i <= m;i++)
cin >> b[i];
sort(b + 1, b + m + 1);
if (m < k || a[1] < k)
cout << "Impossible";
else {
int ans = 1e9;
for (int mask = 1;mask < (1 << m);mask++) {
int x = __builtin_popcount(mask);
if (x < k)
continue;
int s = 0, is = 0, all = 0;
for (int i = 0;i < m;i++) {
if (mask >> i & 1) {
all += b[i + 1];
if (s < n * k) {
is += 1;
s += min(n * k - s, min(b[i + 1], n));
}
}
}
if (all >= sum && s == n * k)
ans = min(ans, all - sum);
}
if (ans >= 1e9)
cout << "Impossible\n";
else
cout << ans << '\n';
}
}
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... |