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;
typedef long long ll;
int N,M;
ll r[200001];
ll l[200001];
int corrisp[200001];
int main() {
cin>>N>>M;
for(int i=0;i<N;i++)cin>>r[i];
for(int i=0;i<M;i++)cin>>l[i];
if(N>M){
swap(N,M);
swap(r,l);
}
sort(r,r+N);
sort(l,l+M);
int a=0,b=M-1;
for(int i=0;i<N/2;i++){
while(a<M-1){
if(abs(l[a]-r[i])>abs(l[a+1]-r[i])&&b-a-1>N-2*i-2)a++;
else break;
}
while(b>0){
if(abs(l[b]-r[N-i-1])>abs(l[b-1]-r[N-i-1])&&b-a-1>N-2*i-2)b--;
else break;
}
corrisp[i]=a;
corrisp[N-i-1]=b;
a++;
b--;
}
if(N%2){
ll mini=abs(l[a]-r[N/2]);
int pos=a;
for(int i=a+1;i<=b;i++){
if(mini>abs(l[i]-r[N/2])){
mini=abs(l[i]-r[N/2]);
pos=i;
}
}corrisp[N/2]=pos;}
ll mini=abs(r[0]-l[corrisp[0]]);
for(int i=1;i<N;i++)mini=max(abs(r[i]-l[corrisp[i]]),mini);
cout<<mini;
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... |