fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6. bool f(int mid, vector<int> &b , vector<int> &a){
  7. for(int i=0;i<a.size();i++){
  8.  
  9. auto it =lower_bound(b.begin(),b.end(),a[i]);
  10. int mi=1e9;
  11. if(it!=b.end()) mi=min(mi,abs(a[i]-*it));
  12. if(it!=b.begin()) mi=min(mi,abs(a[i]-*(--it)));
  13.  
  14. if(mi>mid) return false;
  15. }
  16. return true;
  17. }
  18.  
  19. void solve() {
  20.  
  21. int n,m;
  22. cin >> n >> m;
  23. vector<int> cities(n),towers(m);
  24. for(int i=0;i<n;i++) cin >> cities[i];
  25. for(int i=0;i<m;i++) cin >> towers[i];
  26.  
  27. int high=1e9,low=0,ans=0;
  28.  
  29. while(low<=high){
  30. int mid = (low+high)/2;
  31. if(f(mid,towers,cities)){
  32. ans =mid;
  33. high=mid-1;
  34. }
  35. else
  36. low=mid+1;
  37. }
  38.  
  39. cout << ans << '\n';
  40. }
  41.  
  42. int main(){
  43. ios::sync_with_stdio(false);
  44. cin.tie(nullptr);
  45.  
  46. /*int t;
  47.   cin >> t;
  48.   while (t--)*/ solve();
  49.  
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5320KB
stdin
3 2
-2 2 4
-3 0
stdout
4