#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
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;
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
4152 KB |
Output is correct |
2 |
Correct |
38 ms |
4412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
4248 KB |
Output is correct |
2 |
Correct |
42 ms |
4236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
3664 KB |
Output is correct |
2 |
Correct |
27 ms |
2520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
4024 KB |
Output is correct |
2 |
Correct |
19 ms |
3000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
3648 KB |
Output is correct |
2 |
Correct |
34 ms |
3972 KB |
Output is correct |