#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
const int mod = 1e9+7;
using namespace std;
bool comp(pair<int,int>&a ,pair<int,int>&b)
{
if(a.first==b.first)
{
return a.second>b.second;
}
return a.first<b.first;
}
int gans(int n,int m,int arr[],int arr2[])
{
int tans=0;
bool vis1[100005]={};
int c=0;
for(int i=0;i<n;i++)
{
int t=1e13;
int ind=0;
for(int j=0;j<m;j++)
{
if(vis1[j])continue;
if(abs(arr[i]-arr2[j])<=t)
{
t=abs(arr[i]-arr2[j]);
ind = j;
}
}
vis1[ind]=1;
c++;
tans=max(tans,t);
if(c>=min(n,m))
{
break;
}
}
return tans;
}
void solve()
{
int n,m;
cin>>n>>m;
int arr[100005],arr2[100005];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<m;i++)
{
cin>>arr2[i];
}
int ans=1e13;
sort(arr,arr+n);
sort(arr2,arr2+m);
ans=min(ans,gans(n,m,arr,arr2));
ans=min(ans,gans(m,n,arr2,arr));
reverse(arr,arr+n);
ans=min(ans,gans(n,m,arr,arr2));
ans=min(ans,gans(m,n,arr2,arr));
reverse(arr2,arr2+m);
ans=min(ans,gans(n,m,arr,arr2));
ans=min(ans,gans(m,n,arr2,arr));
reverse(arr2,arr2+m);
ans=min(ans,gans(n,m,arr,arr2));
ans=min(ans,gans(m,n,arr2,arr));
cout<<ans<<endl;
}
int32_t main(){
int t=1;
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//cin>>t;
while(t--){solve();}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
1876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1098 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
1868 KB |
Output is correct |
2 |
Correct |
247 ms |
1944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1868 KB |
Output is correct |
2 |
Correct |
245 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
222 ms |
1952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
227 ms |
1952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
249 ms |
1868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |