local mfl, mce = math.floor, math.ceil local n, k, p = io.read("*n", "*n", "*n") local a, b = {}, {} for i = 1, n do a[i] = io.read("*n") end for i = 1, n do b[i] = io.read("*n") end table.sort(a) table.sort(b) local function solve(x) local c1 = 0 local apos = n for i = 1, n do while 0 < apos and x < a[apos] + b[i] do apos = apos - 1 end if apos == 0 then break end c1 = c1 + apos end apos = n local c2 = 0 for i = 1, n do while 0 < apos and p - 1 < a[apos] + b[i] do apos = apos - 1 end if apos == 0 then break end c2 = c2 + apos end apos = n local c3 = 0 for i = 1, n do while 0 < apos and p + x < a[apos] + b[i] do apos = apos - 1 end if apos == 0 then break end c3 = c3 + apos end return k <= c3 - c2 + c1 end local min, max = -1, p - 1 while 1 < max - min do local mid = mfl((min + max) / 2) if solve(mid) then max = mid else min = mid end end print(max)