#include <bits/stdc++.h>
using namespace std;
const int mxN = 307;
int a[mxN], b[mxN], og_a[mxN], og_b[mxN];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
if (m < k) {
cout << "Impossible\n";
exit(0);
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
og_a[i] = a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
og_b[i] = b[i];
}
sort(b, b + m);
int ind = 0;
set<int> used;
for (int i = 0; i < n; ++i) {
for (int j = ind; j < ind + k; ++j) {
if (j >= m) {
cout << "Impossible\n";
exit(0);
}
used.insert(j);
b[j]--;
a[i]--;
}
if (a[i] < 0) {
cout << "Impossible\n";
exit(0);
}
if (!b[ind]) {
++ind;
}
while (a[i]) {
used.insert(ind);
if (a[i] >= b[ind]) {
a[i] -= b[ind];
++ind;
}
else {
b[ind] -= a[i];
a[i] = 0;
}
}
}
int sum_b = 0;
for (auto x : used) {
sum_b += og_b[x];
}
for (int i = 0; i < n; ++i) {
sum_b -= og_a[i];
}
cout << sum_b << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |