This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// isA AC
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ACPLS(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#define tc int tttttt;cin>>tttttt;while(tttttt--)
#define sumrange(l,r,arr) (l==0?arr[r]:arr[r]-arr[l-1])
bool isint(const string& s){
bool ok=1;
for(char i:s)
ok&=isdigit(i);
return ok;
}
bool isseq(const string& s){
return !isint(s);
}
int main(){
ACPLS();
int n,m;
cin>>n>>m;
vector<int>a;
if(n<=m){
a.resize(n);
for(auto&i:a)cin>>i;
multiset<int>b;
for(int i = 0; i < m; i++){
ll x;
cin>>x;
b.insert(x);
}
int lo=0,hi=1e9,ans=hi;
sort(a.begin(), a.end());
while(lo<=hi){
ll mid=(lo+hi)/2;
multiset<int>ms=b;
bool ok = 1;
for(int i = 0; i < n; i++){
if(ms.empty())break;
auto it = ms.lower_bound(a[i]-mid);
if(it==ms.end()||abs((*it)-a[i])>mid){
ok=0;
break;
}
ms.erase(it);
}
if(ok){
ans=mid;
hi=mid-1;
}else lo=mid+1;
}
cout<<ans;
}
else{
a.resize(m);
multiset<int>b;
for(int i = 0; i < n; i++){
ll x;
cin>>x;
b.insert(x);
}
for(auto&i:a)cin>>i;
int lo=0,hi=1e9,ans=hi;
sort(a.begin(), a.end());
while(lo<=hi){
ll mid=(lo+hi)/2;
multiset<int>ms=b;
bool ok = 1;
for(int i = 0; i < m; i++){
if(ms.empty())break;
auto it = ms.lower_bound(a[i]-mid);
if(it==ms.end()||abs((*it)-a[i])>mid){
ok=0;
break;
}
ms.erase(it);
}
if(ok){
ans=mid;
hi=mid-1;
}else lo=mid+1;
}
cout<<ans;
}
}
# | 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... |