#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, p; long long 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(b.begin(), b.end()); int ng = -1, ok = p; while (ok - ng > 1) { int mid = (ok + ng) / 2; long long cnt = 0; for (int ai : a) { // ai + bj <= mid auto it = lower_bound(b.begin(), b.end(), mid - ai + 1); cnt += it - b.begin(); // p <= ai + bj <= p + mid auto it_1 = lower_bound(b.begin(), b.end(), p + mid - ai + 1); auto it_2 = lower_bound(b.begin(), b.end(), p - ai); cnt += it_1 - it_2; } if (cnt >= k) { ok = mid; } else { ng = mid; } } cout << ok << endl; }