#include <bits/stdc++.h>
using namespace std;
#define ll int
#define vl vector<ll>
#define pll pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define ff(aaa, bbb, ccc) for(ll aaa = bbb; aaa < ccc; aaa++)
#define ed "\n"
int main(){
ll n, m, k;
cin >> n >> m >> k;
vl arr(n), brr(m);
ll ma = 0;
ff(i, 0, n){
cin >> arr[i];
ma = max(ma, arr[i]);
}
set<ll> st;
map<ll, ll> mp;
ll qqqq = 0;
ff(i, 0, m){
cin >> brr[i];
qqqq = max(qqqq, brr[i]);
mp[brr[i]]++;
st.insert(brr[i]);
}
if(ma > qqqq){
cout << "Impossible";
return 0;
}
ff(i, 0, n){
ll p = arr[i];
bool ok = false;
for(auto pos = st.begin(); pos != st.end(); pos++){
if(*pos >= p){
ll cur = *pos, left = cur-p;
ok = true;
mp[cur]--;
if(mp[cur] == 0){
pos = st.erase(pos);
if(left != 0){
st.insert(left);
mp[left]++;
}
}
else{
if(left != 0){
st.insert(left);
mp[left]++;
}
}
break;
}
}
if(!ok){
cout << "Impossible";
return 0;
}
}
ll c = 0;
for(auto &pos : st){
c += pos*mp[pos];
}
cout << c;
}
# | 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... |