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>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
using namespace std;
const int N = 100001 , MOD = 1e9+7;
const double EPS=1e-10, PI=3.141592653589793238462643383279502;
vector<int>a,b;
bool fun(int k)
{
int j = 0;
for(int i = 0 ; i < a.size() ; i ++)
{
while(j<b.size() && a[i]-k>b[j]) j++;
if(j==b.size() || a[i]+k<b[j]) return 0;
j++;
}
return 1;
}
int32_t main()
{
//freopen("abc.in", "r", stdin);
fast;
int n,m,x;
cin>>n>>m;
for(int i = 0 ; i < n ; i ++) cin>>x,a.push_back(x);
for(int i = 0 ; i < m ; i ++) cin>>x,b.push_back(x);
sort(all(a));
sort(all(b));
if(a.size()>b.size()) swap(a,b);
int l = 0 , r = 1e9 , ans=0;
while(l<=r){
int mid=(l+r)/2;
if(fun(mid)){
ans=mid;
r=mid-1;
}
else l=mid+1;
}
cout<<ans;
}
Compilation message (stderr)
cipele.cpp: In function 'bool fun(long long int)':
cipele.cpp:13:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i = 0 ; i < a.size() ; i ++)
| ~~^~~~~~~~~~
cipele.cpp:15:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | while(j<b.size() && a[i]-k>b[j]) j++;
| ~^~~~~~~~~
cipele.cpp:16:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if(j==b.size() || a[i]+k<b[j]) 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... |