#yukicoder423D The Early Bird Catches The Worm N, H = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 #累積和を取っておく なんかに使うと思う C = [0] * (N + 1) D = [0] * (N + 1) for i in range(N): C[i + 1] = A[i] + C[i] D[i + 1] = B[i] + D[i] Rt = sat = hel = 0 for Lt in range(N): #1. 区間Lt - 1を捨てる if Lt: sat -= A[Lt - 1] #[Lt - 1: Rt)の疲労度が1日分回復 hel -= D[Rt] - D[Lt - 1] if Lt > Rt: sat = hel = 0 Rt = Lt #2. 疲れが限界を迎えるまで伸ばす while True: if Rt == N: break #Rtを追加したときの疲労度変化をシミュレート nxt = hel + B[Rt] * (Rt + 1 - Lt) if nxt <= H: hel = nxt sat += A[Rt] Rt += 1 else: break ans = max(ans, sat) print(ans)