#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pdd = pair<ld, ld>; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pil = pair<int, ll>; template <typename T> using Graph = vector<vector<T>>; const int MOD = 1e9 + 7; const ld PI = acos(-1); int main() { cin.tie(0); ios::sync_with_stdio(false); int N, P; ll K; cin >> N >> K >> P; vector<int> A(N), B(N); for (int i = 0; i < N; ++i) cin >> A[i]; for (int i = 0; i < N; ++i) cin >> B[i]; sort(A.begin(), A.end()); sort(B.begin(), B.end()); // <= x: >= K auto isok = [&](ll x) -> bool { ll cnt = 0; for (int i = 0; i < N; ++i) { if (A[i] < P) { cnt += upper_bound(B.begin(), B.end(), x - A[i]) - B.begin(); } cnt += max<int>(upper_bound(B.begin(), B.end(), x - A[i] + P) - lower_bound(B.begin(), B.end(), P - A[i]), 0); } return cnt >= K; }; ll ok = 1e9, ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; (isok(mid) ? ok : ng) = mid; } cout << ok << endl; return 0; }