// #define _GLIBCXX_DEBUG #include #include #define rep(i, n) for (long long i = 0; i < (n); i++) #define rep1(i, n) for(long long i = 1; i <= (n); i++) #define all(v) v.begin(),v.end() #define decimal(n) cout << fixed << setprecision(n); using namespace std; using namespace atcoder; using ll = long long; using vl = vector; using P = pair; using vvl = vector; using vc = vector; using vvc = vector; // using mint = modint998244353; using mint = modint1000000007; const ll MOD = 1000000007; const ll MAX = 2000100; const ll inf = 3e18; const long double pi = acos(-1); templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } ll lcm(ll a,ll b){ return (a*b) / gcd(a,b); } ll n,k,p; vl a,b; //ここに適切な判断条件を書く bool isOK(ll index){ ll cnt = 0; rep(i, n){ cnt += upper_bound(all(b), index - a[i]) - b.begin(); cnt += upper_bound(all(b), p + index - a[i]) - lower_bound(all(b), p - a[i]); } if(cnt >= k) return true; return false; } //臨機応変に引数を書き換える ll binary_search() { //どっちがngか,どっちがokか認識しているか? //探索範囲の上限,下限をしっかり理解しているか? ll ng = -1; ll ok = p - 1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid)) ok = mid; else ng = mid; } return ok; } int main(){ cin >> n >> k >> p; a.resize(n); b.resize(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; sort(all(a)); sort(all(b)); cout << binary_search() << endl; }