#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
int n,k,m,sum=0,a;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
for(int i=0;i<n;i++){
cin >> a;
sum+=a;
}
vector<int> chef(m);
for(int i=0;i<m;i++){
cin >> chef[i];
}
if(k>m){
cout << "Impossible";
}else if(m==1){
if(chef[0]>=sum){
cout << chef[0]-sum;
}else{
cout << "Impossible";
}
}else{
if(k==1){
if(min(chef[0],chef[1])>=sum){
cout << min(chef[0],chef[1])-sum;
}else if(max(chef[0],chef[1])>=sum){
cout << max(chef[0],chef[1])-sum;
}else if(chef[0]+chef[1]>=sum){
cout << chef[0]+chef[1]-sum;
}else{
cout << "Impossible";
}
}else{
if(chef[0]+chef[1]>=sum && min(chef[0],chef[1])>=n){
cout << chef[0]+chef[1]-sum;
}else{
cout << "Impossible";
}
}
}
}
# | 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... |