提交时间:2026-05-29 19:42:44
运行 ID: 41766
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<ll> a, b; bool check(ll d) { int cnt = 0; int j = 0; for (int i = 0; i < n; i++) { while (j < n && b[j] < a[i] - d) j++; if (j < n && b[j] <= a[i] + d) j++; else cnt++; } return cnt == 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { cin >> n; a.resize(n); b.resize(n); for (auto &x : a) cin >> x; for (auto &x : b) cin >> x; sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll l = 0, r = 1e9, ans = 0; while (l <= r) { ll mid = (l + r) / 2; if (check(mid)) { ans = mid; l = mid + 1; } else { r = mid - 1; } } cout << ans << '\n'; } return 0; }