#include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; const ull MOD = 1000000007; using mll = static_modint<1000000007>; #define rep(i,n) for(int i=0; i<(n); i++) ll N,K,P; vector A,B; ll cntB(ll bound){ if(bound >= 0){ return lower_bound(B.begin(),B.end(),bound) - B.begin(); } return -(ll)(B.end() - lower_bound(B.begin(),B.end(),P+bound)); } ll cnt(ll k){ ll res = 0; for(ll a : A){ ll l = 0, r = k + 1; l -= a; r -= a; res += cntB(r); res -= cntB(l); } return res; } int main(){ cin >> N >> K >> P; A.resize(N); rep(i,N) cin >> A[i]; B.resize(N); rep(i,N) cin >> B[i]; sort(A.begin(),A.end()); sort(B.begin(),B.end()); ll l = 0, r = P; while(r-l > 1){ ll m = (l+r) / 2; if(cnt(m-1) < K) l = m; else r = m; } cout << l << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;