#include <bits/stdc++.h>
#define ll long long
#define to_str to_string
#define pb push_back
#define pp pop_back
using namespace std;
void code() {
int n, m, k; cin >> n >> m >> k;
if(m < n * k) {
cout << "Impossible";
return;
}
vector<int> a;
a.pb(0);
for(int i = 0 ; i < n; i++) {
int x; cin >> x;
a.pb(x);
}
vector<int> b;
b.pb(0);
for(int i = 0; i < m; i++) {
int x; cin >> x;
b.pb(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = 0;
for(int i = 0; i < n; i++) {
int l = 1, r = b.size();
while(l < r) {
int mid = l + r / 2;
if(b[mid] >= a[i]) r = mid;
else l = mid + 1;
}
if(b[l] >= a[i]) {
ans += b[l] - a[i];
vector<int> c;
for(int j = 0; j < b.size(); j++) if(b[i] != b[l]) c.pb(b[i]);
b.clear();
b = c;
continue;
}
cout << "Impossible";
return;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
int t = 1;
// cin >> t;
for(int i = 0; i < t; i++) code();
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... |