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;
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=405;
ll n,m,a,ans;
vector<ll>l,r;
int main(){
//fri("in.txt");
//fro("out.txt");
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a;
l.pb(a);
}
for(int i=0;i<m;i++){
cin>>a;
r.pb(a);
}
sort(l.begin(),l.end());
sort(r.begin(),r.end());
if(n<m){
for(int i=0;i<n;i++){
auto j=lower_bound(r.begin(),r.end(),l[i]);
if(j==r.end())j--;
if(j>r.begin() && abs(*j-l[i])>abs(*(j-1)-l[i]))j--;
// for(auto p:r){
// cout<<p<<" ";
// }
// cout<<endl;
// cout<<(*j)<<" "<<l[i]<<endl;
ans=max(ans,abs(*j-l[i]));
r.erase(j);
}
}
else{
for(int i=0;i<m;i++){
auto j=lower_bound(l.begin(),l.end(),r[i]);
if(j==l.end())j--;
if(j>l.begin() && abs(*j-r[i])>abs(*(j-1)-r[i]))j--;
// for(auto p:l){
// cout<<p<<" ";
// }
// cout<<endl;
// cout<<(*j)<<" "<<r[i]<<endl;
ans=max(ans,abs(*j-r[i]));
l.erase(j);
}
}
cout<<ans;
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... |
# | 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... |