from bisect import bisect_left, bisect_right import sys def main(): input = sys.stdin.readline N, K, P = map(int, input().split()) *A, = map(int, input().split()) *B, = map(int, input().split()) A.sort() B.sort() # x以下の要素の数 def f(x): res = 0 for a in A: # Ai+Bj <= x if a + B[0] <= x: i = bisect_right(B, x - a) res += i # P <= Ai+Bi <= P+x if a + B[0] <= P + x: i = bisect_left(B, P - a) j = bisect_right(B, P + x - a) res += max(0, j - i) return res l = -1 r = P-1 while r - l > 1: m = (l + r) // 2 if f(m) < K: l = m else: r = m print(r) if __name__ == '__main__': main()