提交时间:2026-05-29 20:00:26
运行 ID: 41783
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define debug(...) fprintf(stderr,__VA_ARGS__) inline ll read() { ll x(0),f(1); char c=getchar(); while(!isdigit(c)) { if(c=='-')f=-1; c=getchar(); } while(isdigit(c)) { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } const int N=5050; const int M=8e6+100; const int mod=1e9+7; int n; int a[N],b[N]; bool calc1(int p,int w){ for(int i=1;i<=p;i++){ if(b[n-p+i]-a[i]<w) return false; } return true; } bool calc2(int p,int w){ for(int i=p+1;i<=n;i++){ if(a[i]-b[i-p]<w) return false; } return true; } bool check(int w){ int st=0,ed=n; while(st<ed){ int mid=(st+ed+1)>>1; if(calc1(mid,w)) st=mid; else ed=mid-1; } return calc2(st,w); } signed main() { int T=read(); while(T--){ n=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=read(); sort(a+1,a+1+n); sort(b+1,b+1+n); int st=0,ed=1e9; while(st<ed){//二分答案 int mid=(st+ed+1)>>1; if(check(mid)) st=mid; else ed=mid-1; } printf("%d\n",st); } }