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 endl "\n"
typedef long long int ll;
set<int> s;
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int n,m; cin>>n>>m;
vector<int> v1(n+1),v2(m+1);
for(int i=1; i<=n; i++) {
cin>>v1[i];
}
for(int i=1; i<=m; i++) {
cin>>v2[i];
}
if(n>=m) {
for(int i=1; i<=n; i++) {
s.insert(v1[i]);
}
//cout<<endl;
sort(v2.begin()+1,v2.end());
/*
for(int i=1; i<=m; i++) {
cout<<v2[i]<<" ";
}
cout<<endl;
*/
int ans=0;
for(int i=m; i>=1; i--) {
auto d=s.lower_bound(v2[i]);
auto d2=d;
if(d2!=s.begin()) {
d2--;
}
if(abs(*d-v2[i])<abs(*d2-v2[i])) {
ans=max(ans,abs(*d-v2[i]));
s.erase(*d);
}
else{
ans=max(ans,abs(*d2-v2[i]));
s.erase(*d2);
}
}
cout<<ans<<endl;
}
else{
for(int i=1; i<=m; i++) {
s.insert(v2[i]);
}
//cout<<endl;
sort(v1.begin()+1,v1.end());
/*
for(int i=1; i<=m; i++) {
cout<<v2[i]<<" ";
}
cout<<endl;
*/
int ans=0;
for(int i=n; i>=1; i--) {
auto d=s.lower_bound(v1[i]);
auto d2=d;
if(d2!=s.begin()) {
d2--;
}
if(abs(*d-v1[i])<abs(*d2-v1[i])) {
ans=max(ans,abs(*d-v1[i]));
s.erase(*d);
}
else{
ans=max(ans,abs(*d2-v1[i]));
s.erase(*d2);
}
}
cout<<ans<<endl;
}
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... |