//#include<bits/stdc++.h>
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define N 100005
bitset<N> var;
int main(){
lalala;
int n,m;cin>>n>>m;
int sa[n],sol[m];
for(int i=0;i<n;i++)cin>>sa[i];
for(int i=0;i<m;i++)cin>>sol[i];
sort(sa,sa+n);
sort(sol,sol+m);
if(n==m){
int mx=0;
for(int i=0;i<n;i++)mx=max(mx,abs(sa[i]-sol[i]));
cout<<mx<<endl;
return 0;
}
if(n<m){
int mx=0;
for(int i=n-1;i>-1;i--){
int l=0,r=m-1;
while(l<r){
int mid=(l+r)/2;
//cout<<l<<" "<<r<<" "<<mid<<" "<<sol[mid]<<" "<<sa[i]<<endl;
if(sol[mid]>=sa[i]){
r=mid;
}
else l=mid+1;
}
int a=l,b=l;
if(l!=0)a--;
if(var[a]&&a>i){
a--;
}
while(var[b]&&b!=m-1){
b++;
}
//cout<<a<<" "<<b<<endl;
if(var[a]||abs(sol[b]-sa[i])<abs(sol[a]-sa[i])){
mx=max(mx,abs(sol[b]-sa[i]));
var[b]=1;
}
else{
mx=max(mx,abs(sol[a]-sa[i]));
var[a]=1;
}
}
cout<<mx<<endl;
}
else{
int mx=0;
for(int i=m+1;i>-1;i--){
int l=0,r=n-1;
while(l<r){
int mid=(l+r)/2;
if(sa[mid]>sol[i]){
r=mid;
}
else l=mid+1;
}
int a=l,b=l;
if(l!=0)a--;
if(var[a]&&a>i){
a--;
}
while(var[b]&&b!=n-1){
b++;
}
//cout<<i<<" "<<a<<" "<<b<<endl;
if(var[a]||abs(sa[b]-sol[i])<abs(sa[a]-sol[i])){
mx=max(mx,abs(sa[b]-sol[i]));
var[b]=1;
}
else{
mx=max(mx,abs(sa[a]-sol[i]));
var[a]=1;
}
}
cout<<mx<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1108 KB |
Output is correct |
2 |
Correct |
30 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
980 KB |
Output is correct |
2 |
Correct |
29 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
13 ms |
360 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
13 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |