#include using namespace std; int N, P; long long K; vector A, B; long long get_cnt(int x) { long long cnt = 0; for (auto a : A) { auto i = lower_bound(B.begin(), B.end(), P - a) - B.begin(); // 0 <= E <= x int ok = -1, ng = i; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (a + B[mid] <= x) { ok = mid; } else { ng = mid; } } // P <= E <= P+x int ok2 = i - 1, ng2 = N; while (abs(ok2 - ng2) > 1) { int mid2 = (ok2 + ng2) / 2; if (a + B[mid2] <= P + x) { ok2 = mid2; } else { ng2 = mid2; } } cnt += ok + ok2 - i + 2; } return cnt; } int main() { cin >> N >> K >> P; A.resize(N), B.resize(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; sort(B.begin(), B.end()); int ng = -1, ok = P; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (get_cnt(mid) >= K) { ok = mid; } else { ng = mid; } } cout << ok << endl; return 0; }