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 int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int n,m;
vector<int> a,b;
bool check(int mid){
int j=0;
int p=0;
for(int i=0;i<n;i++){
if(j==m)return 0;
while(j<m){
if(abs(a[i]-b[j])<=mid){
p++;
j++;
break;
}
j++;
}
}
return p==n;
}
signed main(){
cin>>n>>m;
a.resize(n);
b.resize(m);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(n>m){
swap(n,m);
swap(a,b);
}
int hi=1e9,lo=0;
while(hi>=lo){
int mid=(hi+lo)/2;
bool u=check(mid);
if(u){
hi=mid-1;
}
else{
lo=mid+1;
}
}
cout<<lo;
}
/*
4 3
2 39 41 45
39 42 46
*/
# | 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... |