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() C = [0] * (P) for b in B: C[b] += 1 for i in range(1, P): C[i] += C[i - 1] # x以下の要素の数 def f(x): res = 0 for a in A: # Ai+Bj <= x if x - a >= 0: res += C[x - a] # P <= Ai+Bi <= P+x res += C[min(P - 1, P + x - a)] - C[P - a - 1] 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()