N, H = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def calc(m) -> int: a = 0 b = 0 s = 0 for i in range(m): s += B[i] * (i+1) a += A[i] b += B[i] res = 0 if s <= H: res = a for i in range(m, N): s -= b a -= A[i-m] b -= B[i-m] s += B[i] * m a += A[i] b += B[i] if s <= H: res = max(res, a) return res ans = 0 lo = 1 hi = N while lo <= hi: m = (lo + hi) // 2 res = calc(m) #print(f'{res=} {m=}') if res > 0: ans = max(ans, res) lo = m + 1 else: hi = m - 1 print(ans)