#pragma GCC optimize "O3" #include using namespace std; using LL=long long; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) #ifdef DEBUG auto&operator<<(auto&o,pairp){return o<<"("<decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<sync_with_stdio(0); int tests; cin >> tests; REP (test, tests) { int n; cin >> n; vector a(n), b(n); REP (i, n) cin >> a[i]; REP (i, n) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); auto check = [&](int k) { debug(k); vector pref(n), suff(n); REP (i, n) { pref[i] = int(upper_bound(b.begin(), b.end(), a[i] - k) - b.begin() - 1); suff[i] = int(lower_bound(b.begin(), b.end(), a[i] + k) - b.begin()); } debug(pref); debug(suff); REP (l, n) { FOR (r, l, n - 1) { if (pref[r] + 1 + (n - suff[l]) < r - l + 1) { return false; } } } return true; }; int bp = 0, bk = 1e9 + 1; while (bk - bp > 1) { int bs = (bp + bk) / 2; if (check(bs)) { bp = bs; } else { bk = bs; } } cout << bp << '\n'; } }