#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()) // auto&operator<<(auto&o,pairp) { // return o << "(" << p.first << ", " << p.second << ")"; // } // auto operator(auto&o, auto x)->decltype(x.end(),o){ // o<<"{";inti=0;for(auto e:x)o<<", "+!i++<> &adj; vector mat, vis; int t = 0, ans = 0; bool mat_dfs(int v) { vis[v] = t; for (int u : adj[v]) { if (mat[u] == -1) { mat[u]= v; mat[v] = u; return true; } } for (int u : adj[v]) { if (vis[mat[u]] != t && mat_dfs(mat[u])) { mat[u] = v; mat[v] = u; return true; } } return false; } Matching(vector>& _adj) : adj(_adj) { mat = vis = vector(ssize(adj), -1); } pair> operator()() { int d = -1; while (d != 0) { d = 0, ++t; REP(v, ssize(adj)) if (mat[v] == -1) d += mat_dfs(v); ans += d; } return {ans, mat}; } }; bool ok(int ile, const vector& A, const vector& B) { // buduje graf, akceptuje tylko wierzcholki o roznicy abs(x, y) >= ile // cout << "Testuje teze " << ile << endl; vector> adj(A.size() + B.size()); const int offset = A.size(); for (int i = 0; i < A.size(); i++) { // cout << "Sasiedzi " << A[i] << endl; for (int j = 0; j < B.size(); j++) { if (abs(A[i] - B[j]) >= ile) { // cout << B[j] << ","; adj[i].push_back(j + offset); adj[j + offset].push_back(i); } // cout << endl; } } // cout << "Stworzony graf: \n"; // for (auto sas : adj) { // for (auto x : sas) { // cout << x << ", "; // } // cout << endl; // } // cout << "\n"; Matching m(adj); auto [m_size, match] = m(); // if (m_size == A.size()) { // cout << "OK\n"; // } else { // cout << "ZLE\n"; // } return m_size == A.size(); } void solve() { int n; cin >> n; vector A(n); vector B(n); for (int i = 0; i < n; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { cin >> B[i]; } // binsercz po wyniku int pocz = 0; int kon = 1e9 + 5; int mid; while (pocz < kon) { mid = (pocz + kon + 1) / 2; if (!ok(mid, A, B)) { // cout << "Teza " << mid << "nie ok\n"; kon = mid - 1; } else { // cout << "Teza " << mid << "ok\n"; pocz = mid; } } cout << pocz << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t --> 0) { solve(); } }