#include using namespace std; #include using namespace atcoder; using ll = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using VS = vector; using P = pair; using VP = vector

; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define out(x) cout << x << endl #define dout(x) cout << fixed << setprecision(10) << x << endl #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(x) (int)(x.size()) #define re0 return 0 #define pcnt __builtin_popcountll template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int inf = 1e9; constexpr ll INF = 1e18; //using mint = modint1000000007; using mint = modint998244353; int di[4] = {1,0,-1,0}; int dj[4] = {0,1,0,-1}; int main(){ ll n,k,p; cin >> n >> k >> p; VL a(n),b(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; sort(all(b)); b.push_back(INF); auto f = [&](ll x){ ll res = 0; rep(i,n){ auto itr1 = upper_bound(all(b),x-a[i]); res += itr1-b.begin(); auto itr2 = upper_bound(all(b),p-1-a[i]); auto itr3 = upper_bound(all(b),p+x-a[i]); res += (itr3-b.begin())-(itr2-b.begin()); //cout << itr1-b.begin() << ' ' << itr2-b.begin() << ' ' << itr3-b.begin() << ' ' << endl; } return res; }; ll ok = p,ng = -1; while(abs(ok-ng) > 1){ ll mid = (ok+ng)/2; //cout << mid << ' ' << f(mid) << endl; if(f(mid) >= k) ok = mid; else ng = mid; } out(ok); }