// Saarland University: <(OvO)> #include #define sz(a) ((int)(a).size()) #define divceil(a, b) ((a) + (b) - 1) / (b) using namespace std; #ifdef ONPC string to_string(const char* s) { return s; } template string to_string(const T& cont) { string ans = ""; for (bool fst = true; const auto& val: cont) { if (!fst) { ans += ", "; } ans += to_string(val); fst = false; } return ans + "}"; } void debug_print_collection() { cerr << endl; } template void debug_print_collection(First val, Args... args) { cerr << " " << to_string(val); debug_print_collection(args...); } #define debug(...) { cerr << "@@@ [" << #__VA_ARGS__ << "] ="; debug_print_collection(__VA_ARGS__);} #else #define debug(...) ; #define NDEBUG #endif mt19937 rnd(123); typedef long long ll; typedef long double ld; int solve() { int n; if (!(cin >> n)) { return 1; } vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0; j < n; j++) { cin >> b[j]; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll len = 1e9 + 7; for (int i = 0; i < n; i++) { int pi = 0; while (pi < n && b[pi] < a[i] + len) { pi++; } int pj = n - 1; for (int j = i; j < n; j++) { while (pj >= 0 && b[pj] > a[j] - len) { pj--; } while (pj + 1 < n && b[pj + 1] <= a[j] - len) { pj++; } //debug(i, j, pi, pj, len); while (j - i + 1 > n - (pi - pj - 1)) { ll nxtlen = 0; if (pi - 1 >= 0) { nxtlen = max(nxtlen, b[pi - 1] - a[i]); } if (pj + 1 < n) { nxtlen = max(nxtlen, a[j] - b[pj + 1]); } //debug(nxtlen); len = nxtlen; while (pj >= 0 && b[pj] > a[j] - len) { pj--; } while (pj + 1 < n && b[pj + 1] <= a[j] - len) { pj++; } while (pi < n && b[pi] < a[i] + len) { pi++; } while (pi > 0 && b[pi - 1] >= a[i] + len) { pi--; } } } } cout << len << '\n'; return 0; } int32_t main() { #ifdef ONPC assert(freopen("B.txt", "r", stdin)); #endif int TET = 1e9; cin >> TET; for (int i = 1; i <= TET; i ++) { if (solve()) { break; } #ifdef ONPC cout << "__________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif } /* g++ -std=c++20 -Wall -Wextra -Wshadow -D_GLIBCXX_DEBUG -DONPC -O2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -o ex template.cpp && ./ex */