N, K, P = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
B = sorted(list(map(int, input().split())))
LTP = 0  # less than P
j = 0
for i in range(N):
    while j < N and A[i] + B[j] < P: j += 1
    LTP += j

L = 0
R = P - 1
while L != R:
    M = (L + R) // 2
    Count = -LTP
    j = 0
    for i in range(N):
        while j < N and A[i] + B[j] <= M: j += 1
        Count += j
    j = 0
    for i in range(N):
        while j < N and A[i] + B[j] <= M + P: j += 1
        Count += j
    if Count < K: L = M + 1
    else: R = M
print(L)