from collections import deque N,H = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) rui = [] for i,v in enumerate(B): if i == 0: rui.append(v) else: rui.append(rui[-1]+v) #print("rui") #print(rui) #print("B") #print(B) #print("A") #print(A) #print() Q1,Q2 = deque(list(range(N))),deque() tired = 0 manzoku = 0 ans = 0 for i,v in enumerate(B): while Q1: if (len(Q2)+1)*B[Q1[0]] + tired <= H: tired += (len(Q2)+1)*B[Q1[0]] manzoku += A[Q1[0]] Q2.append(Q1.popleft()) else: break ans = max(ans,manzoku) # print("before","Q2",Q2,"tired",tired,"manzoku",manzoku) if len(Q2): nex1 = Q2[0] nex2 = Q2[-1] tired -= rui[nex2] if nex1 != 0: tired += rui[nex1-1] manzoku -= A[nex1] Q2.popleft() else: Q1.popleft() # print("after","Q2",Q2,"tired",tired,"manzoku",manzoku) # print() print(ans)