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;
vector<int> ljev;
vector<int> desn;
int uzmi;
int maks=-1;
int zamj=1e9+10;
int l,r;
int main(){
cin>>l>>r;
for(int i=0;i<l;i++){
int br;
cin>>br;
ljev.push_back(br);
}
for(int i=0;i<r;i++){
int br;
cin>>br;
desn.push_back(br);
}
sort(ljev.begin(),ljev.end());
sort(desn.begin(),desn.end());
if(l>r){
uzmi=ljev[0];
ljev.erase(ljev.begin());
for(int i=0;i<r;i++){
if(abs(ljev[i]-desn[i])>maks)maks=abs(ljev[i]-desn[i]);
if(abs(uzmi-desn[i])<maks){
if(abs(ljev[i]-desn[i])>zamj){
maks=zamj;
zamj=abs(ljev[i]-desn[i]);
}
else if(zamj==1e9+10){
zamj=ljev[i]-desn[i];
maks=abs(uzmi-desn[i]);
}
}
}
}
else if(r>l){
uzmi=desn[0];
desn.erase(desn.begin());
for(int i=0;i<l;i++){
if(abs(ljev[i]-desn[i])>maks)maks=abs(ljev[i]-desn[i]);
if(abs(uzmi-ljev[i])<maks){
if(abs(ljev[i]-desn[i])>zamj){
maks=zamj;
zamj=abs(ljev[i]-desn[i]);
}
else if(zamj==1e9+10){
zamj=ljev[i]-desn[i];
maks=abs(ljev[i]-uzmi);
}
}
}
}else{
for(int i=0;i<l;i++){
if(abs(ljev[i]-desn[i])>maks)maks=abs(ljev[i]-desn[i]);
}
}
cout<<maks;
}
# | 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... |
# | 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... |