n, h = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) maxv, sat, tired, curr_tired, r = 0, 0, 0, 0, 0 for l in range(n): while r < n and tired + curr_tired + b[r] <= h: curr_tired += b[r] tired += curr_tired sat += a[r] r += 1 maxv = max(maxv, sat) if r > l: tired -= curr_tired curr_tired -= b[l] sat -= a[l] print(maxv)