N, H = map(int, input().split()) # Reading N and H A = list(map(int, input().split())) B = list(map(int, input().split())) # Prepare cumulative sum of B S = [0] * (N + 1) for i in range(N): S[i + 1] = S[i] + B[i] # Solve using sliding window method ans = 0 tmp = 0 need_hp = 0 r = 0 for l in range(N): while r < N and need_hp + B[r] * (r - l + 1) <= H: tmp += A[r] need_hp += B[r] * (r - l + 1) r += 1 # Debugging output (optional) # print(l, r, need_hp, tmp) # Changing Maximum ans = max(ans, tmp) # Preparing for incrementing l if l == r: r += 1 else: tmp -= A[l] need_hp -= S[r] - S[l] # Cumulative sum for O(1) update # Output print(ans)