fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define nmax 100005
  5. int a[nmax] , b[nmax];
  6. int n , m;
  7. bool check(ll r) {
  8. ll j = 1; // trỏ vào b[]
  9. for (int i = 1; i <= n; ++i) {
  10. // Tìm b[j] gần nhất bên trái hoặc chính giữa
  11. while(j + 1 <= m and abs(b[j] - a[i]) >= abs(b[j + 1] - a[i])){
  12. j++;
  13. }
  14. if (abs(b[j] - a[i]) > r) return false;
  15. }
  16. return true;
  17. }
  18.  
  19. void solve(){
  20. cin >> n >> m;
  21. for (int i = 1 ; i <= n ;i++){
  22. cin >> a[i];
  23. }
  24. sort(a+1 , a+n+1);
  25. for (int i = 1 ;i <= m ;i++){
  26. cin >> b[i];
  27. }
  28. ll dau = 0 , cuoi = 1e18 , kq = 0;
  29. while(dau <= cuoi){
  30. ll mid = (dau + cuoi)/2;
  31. if (check(mid)){
  32. kq = mid;
  33. cuoi = mid - 1;
  34. }
  35. else{
  36. dau = mid + 1;
  37. }
  38. }
  39. cout << kq;
  40. }
  41. int main(){
  42. solve();
  43. }
  44.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty