n,k = map(int, input().split()) a = list(map(int, input().split())) c = list(map(int, input().split())) ans = 0 for i in range(n): aa = a[i:] + a[:i] cc = c[i:] + c[:i] ok = [cc[0]] now = aa[0] for j in range(1, n): ok2 = [] for v in ok: if(cc[j]-k <= v and v <= cc[j]+k): ok2.append(v) if(len(ok2)==0): break ok.append(cc[j]) now+=aa[j] #print(i,j,ok2, now) #ok = ok2 ans = max(ans, now) #print(i, ans) print(ans)