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>
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 |
---|
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... |