#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pdd = pair; using pll = pair; using pli = pair; using pil = pair; template using Graph = vector>; 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 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(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; }