N,K,P = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) imos = [0]*(P+1) for i in range(N): imos[B[i]+1] += 1 for i in range(P): imos[i+1] += imos[i] left = -1 right = P-1 while left+1 < right: mid = (left+right)//2 cnt = 0 for i in range(N): l = -A[i] r = mid-A[i] if r < 0: cnt += imos[r+P+1]-imos[l+P] else: cnt += imos[r+1]+imos[P]-imos[l+P] if cnt >= K: right = mid else: left = mid print(right)