Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells a_{i} theorems during the i-th minute.

Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then t_{i} will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — a_{i} during the i-th minute. Otherwise he writes nothing.

You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that $j \in [ i, i + k - 1 ]$ and will write down all the theorems lecturer tells.

You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.


-----Input-----

The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 10^5) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.

The second line of the input contains n integer numbers a_1, a_2, ... a_{n} (1 ≤ a_{i} ≤ 10^4) — the number of theorems lecturer tells during the i-th minute.

The third line of the input contains n integer numbers t_1, t_2, ... t_{n} (0 ≤ t_{i} ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.


-----Output-----

Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.


-----Example-----
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0

Output
16



-----Note-----

In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.

Difficulty: EASY
Tags: Dynamic programming

Amortized analysis

Data structures

Implementation
Skill types: Dynamic programming

Data structures

Amortized analysis
Expected Time Complexity: O(N)

Starter code:

Solutions:
(n, k) = map(int, input().split(' '))
(lt, ls) = (list(map(int, input().split(' '))), list(map(int, input().split(' '))))
s = 0
for i in enumerate(lt):
	if ls[i[0]]:
		s += i[1]
		lt[i[0]] = 0
curr_s = sum(lt[:k])
mx = curr_s
for i in range(1, n - k + 1):
	temp = curr_s - lt[i - 1] + lt[i + k - 1]
	curr_s = temp
	if temp > mx:
		mx = temp
print(s + mx)


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
p1 = 0
m = 0
cur = 0
for i in range(a[0] - 1, -1, -1):
	if c[i] == 1:
		p1 += b[i]
	if c[i] == 0:
		cur += b[i]
	if i + a[1] < a[0]:
		if c[i + a[1]] == 0:
			cur -= b[i + a[1]]
			if cur < 0:
				cur = 0
	if cur > m:
		m = cur
print(p1 + m)


R = lambda : map(int, input().split())
(n, k) = R()
ds = tuple(zip(R(), R()))
s = sum((x * y for (x, y) in ds))
m = d = sum((x * (1 - y) for (x, y) in ds[:k]))
for i in range(n - k):
	d = d + ds[i + k][0] * (1 - ds[i + k][1]) - ds[i][0] * (1 - ds[i][1])
	m = max(m, d)
print(s + m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [0]
x = [0]
for i in a:
	x.append(x[-1] + i)
for i in range(n):
	dp.append(dp[-1] + a[i] * b[i])
ans = 0
for i in range(1, n + 1):
	c = i
	y = i - k
	y = max(y, 0)
	ans = max(ans, x[c] - x[y] + dp[y] + dp[n] - dp[i])
print(ans)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, k) = mints()
a = list(mints())
b = list(mints())
d = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	d[i] = d[i + 1] + a[i] if b[i] == 1 else d[i + 1]
c = 0
for i in range(k):
	c += a[i]
r = c + d[k]
s = 0
for i in range(k, n):
	c += a[i]
	c -= a[i - k]
	if b[i - k]:
		s += a[i - k]
	r = max(r, s + c + d[i + 1])
print(r)


I = lambda : map(int, input().split())
(n, k) = I()
(a, t, m) = (list(I()), list(I()), 0)
for i in range(n):
	if t[i] == 1:
		m += a[i]
		a[i] = 0
r = sum(a[:k])
l = [r] * n
for i in range(1, n - k + 1):
	r -= a[i - 1] - a[i + k - 1]
	l[i] = r
print(max(l[:n - k + 1]) + m)


(duracao_da_palestra, tempo_acordado) = map(int, input().split())
num_de_teoremas = list(map(int, input().split()))
comportamento = list(map(int, input().split()))
num_max_de_teoremas = 0
for i in range(duracao_da_palestra):
	num_max_de_teoremas += num_de_teoremas[i] * comportamento[i]
	if comportamento[i] == 0:
		if i < tempo_acordado:
			num_max_de_teoremas += num_de_teoremas[i]
(aux, i, j) = (num_max_de_teoremas, 0, tempo_acordado - 1)
while j < duracao_da_palestra - 1:
	if comportamento[j + 1] == 0:
		aux += num_de_teoremas[j + 1]
	if comportamento[i] == 0:
		aux -= num_de_teoremas[i]
	if aux > num_max_de_teoremas:
		num_max_de_teoremas = aux
	i += 1
	j += 1
print(num_max_de_teoremas)


[n, k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
arr = []
arr2 = []
for x in range(len(a)):
	if t[x] == 1:
		arr.append(a[x])
		arr2.append(0)
	else:
		arr.append(0)
		arr2.append(a[x])
pref = [0]
pref2 = [0]
for g in range(len(a)):
	pref.append(arr[g] + pref[g])
	pref2.append(arr2[g] + pref2[g])
maxi = 0
for b in range(n - k + 1):
	val = pref[b + k] - pref[b] + pref2[b + k] - pref2[b]
	if b - 1 >= 0:
		val += pref[b]
	val += pref[len(pref) - 1] - pref[b + k]
	maxi = max(maxi, val)
print(maxi)


n = list(map(int, input().split()))
lecs = list(map(int, input().split()))
beh = list(map(int, input().split()))
value = 0
we = []
k = n[1]
newvalue = 0
maxi = 0
for i in range(n[0]):
	value = value + lecs[i] * beh[i]
	if beh[i] == 1:
		lecs[i] = 0
	if i <= k - 1:
		newvalue = newvalue + lecs[i]
maxi = newvalue
for j in range(k, n[0]):
	newvalue += lecs[j]
	newvalue -= lecs[j - k]
	if newvalue > maxi:
		maxi = newvalue
print(value + maxi)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = 0
for i in range(k):
	if b[i] == 0:
		s += a[i]
r = 0
for i in range(n):
	if b[i] == 1:
		r += a[i]
m = s
for w in range(k, n):
	if b[w] == 0:
		s += a[w]
	if b[w - k] == 0:
		s -= a[w - k]
	if s > m:
		m = s
print(r + m)


t = input().split(' ')
n = int(t[0])
k = int(t[1])
A = input().split(' ')
B = input().split(' ')
for i in range(len(A)):
	A[i] = int(A[i])
	B[i] = int(B[i])
sm = 0
for i in range(len(B)):
	if B[i] == 1:
		sm += A[i]
mx = 0
for i in range(k):
	if B[i] == 0:
		mx += A[i]
cur = mx
for j in range(n - k):
	if B[j] == 0:
		cur -= A[j]
	if B[j + k] == 0:
		cur += A[j + k]
	if cur > mx:
		mx = cur
print(mx + sm)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
(d, e, s, f) = (0, 0, 0, 0)
for i in range(n):
	if m[i]:
		s = s + l[i]
		l[i] = 0
	if i > k - 1:
		e = max(e, d)
		d = d - l[f]
		f = f + 1
	d = d + l[i]
print(s + max(d, e))


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)
(n, m) = mi()
l = li()
t = li()
count = 0
a = []
for i in range(n):
	if t[i] == 1:
		count += l[i]
		l[i] = 0
(h, t) = (0, 0)
for i in range(n):
	t += l[i]
	if i >= m:
		t -= l[i - m]
	h = max(h, t)
print(count + h)


entrada = list(map(int, input().split()))
aula = list(map(int, input().split()))
sono = list(map(int, input().split()))
valor2 = entrada[1]
soma = 0
soma1 = 0
listaAuxiliar = [0] * (entrada[0] + 1)
for i in range(int(entrada[0])):
	if sono[i] == 1:
		soma1 += int(aula[i])
		aula[i] = 0
for i in range(1, entrada[0] + 1):
	listaAuxiliar[i] = listaAuxiliar[i - 1] + aula[i - 1]
contador = valor2
for i in range(len(listaAuxiliar) - valor2):
	soma = max(listaAuxiliar[contador] - listaAuxiliar[i], soma)
	contador += 1
print(soma + soma1)


(n, k) = map(int, input().split())
lections = []
for x in map(int, input().split()):
	lections.append(x)
times = list(map(int, input().split()))
all_Sum = 0
for (i, x) in enumerate(times):
	if x:
		all_Sum += lections[i]
		lections[i] = 0
sUm = sum(lections[:k])
maX = int(sUm)
ans = [0, k - 1]
for i in range(k, len(lections)):
	sUm += lections[i]
	sUm -= lections[i - k]
	if sUm > maX:
		ans = [i - k, i]
		maX = int(sUm)
print(maX + all_Sum)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
total_no_sleep = 0
for i in range(n):
	if t[i] == 1:
		total_no_sleep += a[i]
total_sleep = 0
for i in range(k):
	if t[i] == 0:
		total_sleep += a[i]
max_total_sleep = total_sleep
for i in range(n - k):
	if t[i] == 0:
		total_sleep -= a[i]
	if t[i + k] == 0:
		total_sleep += a[i + k]
	if total_sleep > max_total_sleep:
		max_total_sleep = total_sleep
print(total_no_sleep + max_total_sleep)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
s = 0
for i in range(k):
	if f[i] == 0:
		s += a[i]
max_s = s
for i in range(k, n):
	if f[i] == 0:
		s += a[i]
	if f[i - k] == 0:
		s -= a[i - k]
	max_s = max(s, max_s)
first = 0
for i in range(n):
	first += a[i] * bool(f[i] == 1)
print(max_s + first)


import sys
first_line = sys.stdin.readline().split()
n = int(first_line[0])
k = int(first_line[1])
th = sys.stdin.readline().split()
beh = sys.stdin.readline().split()
summa = 0
for i in range(n):
	th[i] = int(th[i])
	beh[i] = int(beh[i])
	if beh[i] == 1:
		summa += th[i]
		th[i] = 0
maximum = sum(th[0:0 + k])
prev_sum = maximum
for i in range(1, n - (k - 1)):
	next_sum = prev_sum - th[i - 1] + th[i + k - 1]
	if next_sum > maximum:
		maximum = next_sum
	prev_sum = next_sum
print(summa + maximum)


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
c = [x * y for (x, y) in zip(a, b)]
a_ps = [0]
c_ps = [0]
for i in range(n):
	c_ps.append(c_ps[-1] + c[i])
	a_ps.append(a_ps[-1] + a[i])
m = 0
for i in range(n - k + 1):
	m = max(m, c_ps[i] + a_ps[k + i] - a_ps[i] + c_ps[-1] - c_ps[k + i])
print(m)


re = lambda : map(int, input().split())
(a, k) = re()
total = 0
best_wake_up = []
theo = list(re())
status = list(re())
sleep_ind = []
c = 0
current_sleeping_sum = 0
placeholder = []
for (t, s) in zip(theo, status):
	if s:
		total += t
		placeholder.append(0)
	else:
		placeholder.append(t)
	c += 1
extra = 0
if len(placeholder) <= k:
	extra = sum(placeholder)
else:
	start = sum(placeholder[:k])
	extra = max(extra, start)
	for x in range(a - k):
		start -= placeholder[x]
		start += placeholder[x + k]
		extra = max(extra, start)
print(total + extra)


(t, w) = map(int, input().split())
th = list(map(int, input().split()))
s = list(map(int, input().split()))
pre = [0] * t
_sum = 0
for (i, v) in enumerate(s):
	if i:
		pre[i] += pre[i - 1]
	if v == 0:
		pre[i] += th[i]
	else:
		_sum += th[i]
_max = 0
for i in range(w - 1, t):
	if _max < pre[i] - (pre[i - w] if i >= w else 0):
		_max = pre[i] - (pre[i - w] if i >= w else 0)
print(_sum + _max)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
c = [0 for _ in range(n + 1)]
b = sum([a[i] for i in range(n) if t[i] == 1])
for i in range(n):
	if t[i] == 0:
		c[i + 1] = a[i]
for i in range(1, n + 1):
	c[i] += c[i - 1]
m = 0
for i in range(n - k + 1):
	if c[i + k] - c[i] + b > m:
		m = c[i + k] - c[i] + b
print(m)


from math import ceil, log
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
summ = 0
for i in range(k, n):
	if t[i] == 1:
		summ += a[i]
maxim = sum(a[0:k]) + summ
cur = maxim
r = k
l = 0
while r < n:
	if t[r] == 0:
		cur += a[r]
	if t[l] == 0:
		cur -= a[l]
	maxim = max(maxim, cur)
	r += 1
	l += 1
print(maxim)


def main():
	(n, k) = map(int, input().split())
	(l, b, r) = ([0], 0, 0)
	if n == k:
		print(sum(map(int, input().split())))
		return
	for (a, t) in zip(map(int, input().split()), input()[::2]):
		if t == '1':
			r += a
		else:
			b += a
		l.append(b)
	print(r + max((l[i] - b for (i, b) in zip(range(k, n + 1), l))))
main()


import sys

class MyReader:

	def __init__(self):
		filename = 'file.in'
		if self.isLocal():
			self.file = open(filename)
		self.str = ['']
		self.ind = 1

	def isLocal(self):
		return len(sys.argv) > 1 and sys.argv[1] == 'SCHULLZ'

	def nextString(self):
		if self.isLocal():
			return self.file.read()
		else:
			return input()

	def nextInt(self):
		return int(self.nextToken())

	def nextToken(self):
		if self.ind >= len(self.str):
			self.ind = 0
			self.str = self.nextString().split()
		self.ind += 1
		return self.str[self.ind - 1]
rdr = MyReader()
n = rdr.nextInt()
k = rdr.nextInt()
a = []
isAwake = []
missed = []
for i in range(0, n):
	a.append(rdr.nextInt())
awaken = 0
for i in range(0, n):
	isAwake.append(rdr.nextInt())
	missed.append(0)
	if 0 == isAwake[i]:
		missed[i] = a[i]
	else:
		awaken += a[i]
		missed[i] = 0
tres = 0
for i in range(0, k):
	tres += missed[i]
res = tres
for i in range(k, n):
	tres -= missed[i - k]
	tres += missed[i]
	res = max(res, tres)
sys.stdout.write(str(res + awaken))
sys.stdout.flush()


first_string = input()
first_str_list = list(first_string.split(' '))
n = int(first_str_list[0])
k = int(first_str_list[1])
second_string = input()
second_str_list = list(second_string.split(' '))
theoreme_list = list()
for i in range(0, len(second_str_list)):
	theoreme_list.append(int(second_str_list[i]))
third_string = input()
third_str_list = list(third_string.split(' '))
time_list = list()
for i in range(0, len(third_str_list)):
	time_list.append(int(third_str_list[i]))
pr = list()
overall = 0
for i in range(0, n):
	pr.append(0)
	if i:
		pr[i] += pr[i - 1]
	if time_list[i] == 0:
		pr[i] += theoreme_list[i]
	else:
		overall += theoreme_list[i]
add = 0
for i in range(k - 1, n):
	if i >= k:
		add = max(add, pr[i] - pr[i - k])
	else:
		add = max(add, pr[i] - 0)
print(overall + add)


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cur_sum = 0
max_sum = 0
sum = 0
for i in range(n):
	if b[i] == 1:
		sum += a[i]
	if i < k:
		cur_sum += (1 - b[i]) * a[i]
	else:
		cur_sum += (1 - b[i]) * a[i]
		cur_sum -= (1 - b[i - k]) * a[i - k]
	if cur_sum > max_sum:
		max_sum = cur_sum
print(sum + max_sum)


(n, k) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
t = list(map(int, input().split()))
m = 0
s = 0
temp = 0
for i in range(n):
	m = max(m, temp)
	if i >= k:
		ch = i - k
		if t[ch] == 0:
			temp -= a[ch]
	if t[i] == 0:
		temp += a[i]
	if t[i] == 1:
		s += a[i]
m = max(m, temp)
print(s + m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
minus = []
s = 0
ans = 0
for i in range(n):
	if t[i] == 0:
		minus.append(a[i])
	else:
		minus.append(0)
		ans += a[i]
s = ans
cur = 0
for i in range(k):
	cur += minus[i]
ans += cur
for i in range(1, n - k + 1):
	cur -= minus[i - 1]
	cur += minus[i + k - 1]
	ans = max(s + cur, ans)
print(ans)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
ans = 0
for i in range(n):
	if lst2[i] == 1:
		ans += lst[i]
lst3 = [0] * n
if lst2[0] == 0:
	lst3[0] = lst[0]
for i in range(1, n):
	if lst2[i] == 0:
		lst3[i] = lst[i] + lst3[i - 1]
	else:
		lst3[i] = lst3[i - 1]
best = 0
best = lst3[k - 1]
for i in range(k, n):
	sum1 = lst3[i] - lst3[i - k]
	best = max(sum1, best)
print(ans + best)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
pref_sum = [0] * n
pref_score = [0] * n
for i in range(n):
	pref_sum[i] = pref_sum[i - 1] + a[i]
	pref_score[i] = pref_score[i - 1] + a[i] * t[i]
ans = pref_sum[k - 1] + pref_score[n - 1] - pref_score[k - 1]
for i in range(k, n):
	ans = max(ans, pref_score[i - k] + pref_score[n - 1] - pref_score[i] + pref_sum[i] - pref_sum[i - k])
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
zeros = [0 for i in range(n)]
zero = 0
for i in range(n):
	if t[i] == 0:
		zeros[i] += zeros[max(0, i - 1)] + a[i]
	else:
		zeros[i] = zeros[max(0, i - 1)]
mx = 0
for i in range(n - k + 1):
	if i == 0:
		extra = zeros[i + k - 1]
	else:
		extra = zeros[i + k - 1] - zeros[i - 1]
	if extra > mx:
		mx = extra
ans = mx
for i in range(n):
	if t[i] == 1:
		ans += a[i]
print(ans)


import sys
(n, k) = map(int, next(sys.stdin).split())
tasks = list(map(int, next(sys.stdin).split()))
wakes = list(map(int, next(sys.stdin).split()))

def get_sleep_tasks(wakes, tasks):
	for (wake, task) in zip(wakes, tasks):
		if wake:
			yield 0
		else:
			yield task
answer = 0
for (wake, task) in zip(wakes, tasks):
	answer += wake * task
tasks_sleeps = [(not w) * t for (w, t) in zip(wakes, tasks)]

def by_k(arr, k):
	s = sum(arr[0:k])
	for i in range(0, len(arr) - k):
		yield s
		s -= arr[i]
		s += arr[i + k]
	yield s
max_add = 0
for x in by_k(tasks_sleeps, k):
	if x > max_add:
		max_add = x
print(max_add + answer)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
m = 0
p = [0] * (n + 1)
for i in range(n):
	if a[i] == 1:
		m += l[i]
		p[i + 1] = p[i]
	else:
		p[i + 1] = p[i] + l[i]
g = []
for i in range(k, n + 1):
	g.append(p[i] - p[i - k])
m += max(g)
print(m)


(a, b) = map(int, input().split())
lec = list(map(int, input().split()))
sleep = list(map(int, input().split()))
total = 0
zl = []
for i in range(a):
	if sleep[i] == 1:
		total += lec[i]
		lec[i] = 0
extra = sum(lec[0:b])
m = extra
for i in range(b, a):
	extra += lec[i] - lec[i - b]
	m = max(m, extra)
print(total + m)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	(n, k) = get_ints()
	arr = get_array()
	awake = get_array()
	prefix_sum = [0] * (n + 1)
	ans = 0
	for i in range(1, n + 1):
		prefix_sum[i] += prefix_sum[i - 1]
		if awake[i - 1] == 0:
			prefix_sum[i] += arr[i - 1]
		else:
			ans += arr[i - 1]
	add = 0
	for i in range(k, n + 1):
		x = prefix_sum[i] - prefix_sum[i - k]
		add = max(add, x)
	print(ans + add)
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = 0
for i in range(n):
	if t[i]:
		ans += a[i]
		a[i] = 0
pk = sum(a[:k])
tech = sum(a[:k])
for i in range(n - k):
	pk = pk - a[i] + a[i + k]
	tech = max(tech, pk)
print(ans + tech)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
s = sum(A[:k])
ok = 0
for i in range(n):
	if T[i]:
		ok += A[i]
s_1 = 0
for i in range(k):
	if T[i]:
		s_1 += A[i]
ans = 0
for start in range(k, n):
	ans = max(ans, s - s_1)
	s -= A[start - k]
	s += A[start]
	if T[start - k]:
		s_1 -= A[start - k]
	if T[start]:
		s_1 += A[start]
ans = max(ans, s - s_1)
print(ans + ok)


def potential(a):
	return a[0] if a[1] == 0 else 0

def theorems(a):
	return a[0] if a[1] == 1 else 0
(n, k) = map(int, input().split())
A = list(zip(map(int, input().split()), map(int, input().split())))
awake = 0
for a in A[:k]:
	awake += potential(a)
best = awake
for (i, a) in enumerate(A[k:]):
	awake += potential(a)
	awake -= potential(A[i])
	if awake > best:
		best = awake
already = sum((theorems(a) for a in A))
print(already + best)


R = lambda : map(int, input().split())
(n, k) = R()
(s, t) = (list(R()), list(R()))
r = sum([s[i] for i in range(n) if t[i]])
m = sum([s[i] for i in range(k) if 1 - t[i]])
x = m
for i in range(1, n - k + 1):
	m += -(1 - t[i - 1]) * s[i - 1] + (1 - t[i + k - 1]) * s[i + k - 1]
	x = max(m, x)
print(x + r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sums = [0] * (n + 1)
ans = 0
curr = 0
maxi = 0
for i in range(n):
	if b[i]:
		ans += a[i]
		sums[i + 1] = curr
	else:
		curr += a[i]
		sums[i + 1] = curr
for i in range(n - k + 1):
	maxi = max(maxi, sums[i + k] - sums[i])
print(ans + maxi)


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
t = list(map(int, input().strip().split()))
ps = [0] * (n + 1)
for i in range(n):
	ps[i + 1] = ps[i] + a[i]
pst = [0] * (n + 1)
for i in range(n):
	pst[i + 1] = pst[i] + a[i] * t[i]
res = 0
for i in range(n - k + 1):
	x = ps[i + k] - ps[i]
	y = pst[i] + pst[n] - pst[i + k]
	res = max(res, x + y)
print(res)


from sys import stdin
a = stdin.readline().split()
n = int(a[0])
k = int(a[1])
A = stdin.readline().split()
B = stdin.readline().split()
sum = 0
temp = 0
for l in range(0, len(A)):
	if int(B[l]) == 1:
		sum += int(A[l])
for p in range(0, k):
	if int(B[p]) == 0:
		temp += int(A[p])
MAX = temp
for q in range(k, len(A)):
	if int(B[q - k]) == 0:
		temp -= int(A[q - k])
	if int(B[q]) == 0:
		temp += int(A[q])
	MAX = max(MAX, temp)
print(MAX + sum)


import sys
f = sys.stdin.readline
(n, k) = map(int, f().strip().split())
a = [int(v) for v in f().strip().split()]
mis = [int(v) for v in f().strip().split()]

def get(l, r, n, pre):
	if r >= n:
		r = n - 1
	if l > 0:
		return pre[r] - pre[l - 1]
	return pre[r]

def solve(a, n, mis):
	cur = 0
	for i in range(n):
		if mis[i] == 1:
			cur += a[i]
			a[i] = 0
	pre = [0] * n
	pre[0] = a[0]
	for x in range(1, n):
		pre[x] += pre[x - 1] + a[x]
	ans = 0
	i = 0
	j = 0
	temp = 0
	while i < n:
		temp = get(i, i + k - 1, n, pre)
		ans = max(ans, temp)
		i = i + 1
	return ans + cur
print(solve(a, n, mis))


n = [int(x) for x in input().split(' ')]
teoremas = [int(j) for j in input().split(' ')]
acordada = input().split(' ')
pont2 = int(n[1])
quant = 0
diferenca = 0
soma = [0]
somaAcordada = [0]
for i in range(len(teoremas)):
	soma.append(teoremas[i] + soma[i])
	if acordada[i] == '1':
		somaAcordada.append(teoremas[i] + somaAcordada[i])
	else:
		somaAcordada.append(somaAcordada[i])
for pont1 in range(len(teoremas)):
	if pont2 == len(soma):
		break
	diferenca = soma[pont2] - soma[pont1] - (somaAcordada[pont2] - somaAcordada[pont1])
	pont2 += 1
	quant = max(quant, diferenca)
print(quant + somaAcordada[len(somaAcordada) - 1])


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
awake = list(map(int, input().split()))
answer = 0
for i in range(n):
	if awake[i] == 1:
		answer += arr[i]
		arr[i] = 0
half = 0
total = 0
for i in range(n):
	total += arr[i]
	if i >= k:
		total -= arr[i - k]
	half = max(half, total)
print(answer + half)


n = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
soma = 0
for i in range(n[0]):
	if b[i] == 1:
		soma += a[i]
		a[i] = 0
k = sum(a[0:n[1]])
m = k
for i in range(n[1], n[0]):
	k += a[i] - a[i - n[1]]
	m = max(m, k)
print(soma + m)


def solve(n, k, t, a):
	awake = [0 for i in range(n)]
	awake[0] = t[0]
	for i in range(1, n):
		awake[i] = t[i] + awake[i - 1]
	actual = [0 for i in range(n)]
	actual[0] = t[0] * a[0]
	for i in range(1, n):
		actual[i] = t[i] * a[i] + actual[i - 1]
	m = 0
	for i in range(n - k + 1):
		start_awake = i
		end_awake = i + k - 1
		awake_total = awake[end_awake] - awake[start_awake] + t[start_awake]
		front_end = i - 1
		front_total = 0
		if front_end >= 0:
			front_total = actual[front_end]
		end_start = i + k
		end_total = 0
		if end_start <= n - 1:
			end_total = actual[n - 1] - actual[end_start - 1]
		total = awake_total + front_total + end_total
		m = max(m, total)
	return m
nk = [int(i) for i in input().split()]
n = nk[0]
k = nk[1]
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n, k, t, a))


from collections import defaultdict
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
prefix = defaultdict(int)
i = 0
for (sleep, power) in zip(t, a):
	if sleep == 0:
		prefix[i] = prefix[i - 1]
	else:
		prefix[i] = power + prefix[i - 1]
	i += 1
suffix = defaultdict(int)
k_sum = defaultdict(int)
i = 0
j = 0
total = 0
while i < len(a):
	total += a[i]
	if i - j >= k:
		total -= a[j]
		j += 1
	k_sum[i] = total
	i += 1
for i in range(len(a) - 1, -1, -1):
	if t[i] == 0:
		suffix[i] = suffix[i + 1]
	else:
		suffix[i] = a[i] + suffix[i + 1]
total = sum(a)
ans = 0
for i in range(len(a)):
	between = k_sum[i + k - 1]
	ans = max(prefix[i - 1] + suffix[i + k] + between, ans)
print(ans)


import itertools as it
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
summ = sum([a[i] for i in range(n) if t[i]])
a = [0] + list(it.accumulate([a[i] if not t[i] else 0 for i in range(n)]))
max_ = max([a[i] - a[i - k] for i in range(k, n + 1)])
print(summ + max_)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
cng = [0] * n
ans = 0
cng[0] = (1 - b[0]) * a[0]
for i in range(n):
	ans += a[i] * b[i]
	if i > 0:
		cng[i] = (1 - b[i]) * a[i] + cng[i - 1]
mix = cng[k - 1]
for i in range(1, n - k + 1):
	mix = max(mix, cng[i + k - 1] - cng[i - 1])
print(ans + mix)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
base = 0
for i in range(n):
	base += l[i] * t[i]
	if t[i]:
		l[i] = 0
curr = sum(l[:k])
best = curr
for i in range(k, n):
	curr += l[i]
	curr -= l[i - k]
	best = max(best, curr)
print(best + base)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
su = 0
for i in range(n):
	if b[i]:
		su += a[i]
		a[i] = 0
s = ma = sum(a[:k])
for j in range(0, n - k):
	s = s + a[j + k] - a[j]
	ma = max(ma, s)
print(su + ma)


from copy import deepcopy
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
aux = deepcopy(a)

def bounded_sum(l, k):
	(r, size, i) = (0, 0, 0)
	while size < k:
		r += l[i]
		size += 1
		i += 1
	return r
(soma, max_soma, soma_tot, pos) = (0, 0, 0, -1)
for i in range(n):
	if t[i] == 1:
		a[i] = 0
for j in range(n - k + 1):
	if j == 0:
		soma += bounded_sum(a, k)
	else:
		soma = soma - a[j - 1] + a[j + k - 1]
	if soma > max_soma:
		max_soma = soma
		pos = j
for i in range(len(t)):
	if t[i] == 1 or pos + k - 1 >= i >= pos:
		soma_tot += aux[i]
print(soma_tot)


L = input().split()
(n, m) = map(int, L)
L = input().split()
a = list(map(int, L))
L = input().split()
t = list(map(int, L))
ttot = [0] * (n + 5)
ttot[0] = 0
ta = [0] * (n + 5)
ta[0] = 0
for i in range(n):
	ttot[i + 1] = ttot[i] + a[i]
	ta[i + 1] = ta[i] + a[i] * t[i]
Max = 0
for i in range(n - m + 1):
	tmp = ta[i]
	tmp = tmp + ttot[i + m] - ttot[i]
	tmp = tmp + (ta[n] - ta[i + m])
	if tmp > Max:
		Max = tmp
		pos = i + 1
print(Max)


def calcula_b(aula, sonin):
	tt_beneficio = 0
	for i in range(len(aula)):
		if sonin[i] == 0:
			tt_beneficio += aula[i]
	return tt_beneficio
(t, tamanho_tecnica) = map(int, input().split(' '))
aula = list(map(int, input().split(' ')))
sonin = list(map(int, input().split(' ')))
melhor_posicao = 0
melhor_beneficio = calcula_b(aula[0:tamanho_tecnica], sonin[0:tamanho_tecnica])
beneficio_atual = calcula_b(aula[0:tamanho_tecnica], sonin[0:tamanho_tecnica])
for i in range(1, len(aula) - tamanho_tecnica + 1):
	temporario = 0
	if sonin[i + tamanho_tecnica - 1] == 0:
		temporario += aula[i + tamanho_tecnica - 1]
	if sonin[i - 1] == 0:
		temporario -= aula[i - 1]
	beneficio_atual = beneficio_atual + temporario
	if beneficio_atual > melhor_beneficio:
		melhor_posicao = i
		melhor_beneficio = beneficio_atual
for i in range(melhor_posicao, melhor_posicao + tamanho_tecnica):
	sonin[i] = 1
acumulado = 0
for i in range(len(aula)):
	if sonin[i] == 1:
		acumulado += aula[i]
print(acumulado)


def invert(x):
	if x == 1:
		return 0
	else:
		return 1
(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
t = list(map(int, input().strip().split()))
base = sum([a * b for (a, b) in zip(a, t)])
t = map(invert, t)
t = [a * b for (a, b) in zip(a, t)]
for i in range(1, len(t)):
	t[i] += t[i - 1]
rslt = t[k - 1]
for i in range(1, n - k + 1):
	rslt = max(rslt, t[i + k - 1] - t[i - 1])
print(rslt + base)


(n, k) = map(int, input().split())
l = [*map(int, input().split())]
t = [*map(int, input().split())]
a = [0]
res = 0
for i in range(1, n + 1):
	a.append(a[-1] + l[i - 1] * (t[i - 1] ^ 1))
for i in range(1, n + 1):
	d = a[min(n, i + k - 1)] - a[i - 1]
	res = max(res, d)
print(res + sum(l) - a[-1])


(n, k) = [int(p) for p in input().split()]
th = [int(p) for p in input().split()]
aw = [int(p) for p in input().split()]
try:
	i = aw.index(0)
except ValueError:
	print(sum(th))
	exit()
j = i + k
arr = [sum(th[:k])]
exSum = []
s = 0
for i in range(k):
	if aw[i]:
		s += th[i]
exSum.append(s)
total = 0
for i in range(1, len(th) - k + 1):
	curr = arr[-1]
	curr -= th[i - 1]
	curr += th[i + k - 1]
	arr.append(curr)
	s = exSum[-1]
	if aw[i - 1] == 1:
		s -= th[i - 1]
	if aw[i + k - 1] == 1:
		s += th[i + k - 1]
	exSum.append(s)
(index, m) = (None, 0)
for i in range(len(arr)):
	prev = m
	m = max(m, abs(arr[i] - exSum[i]))
	if prev != m:
		index = i
for i in range(index):
	if aw[i]:
		total += th[i]
for i in range(index + k, len(th)):
	if aw[i]:
		total += th[i]
print(total + arr[index])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
dif = 0
soma = 0
tdif = 0
for c in range(n):
	if t[c] == 1:
		soma += a[c]
		t[c] = 0
	else:
		t[c] = a[c]
for e in range(n):
	if e != 0:
		t[e] = t[e] + t[e - 1]
	else:
		t[e] += 0
for j in range(n - k + 1):
	if j != 0:
		tdif = t[j + k - 1] - t[j - 1]
	else:
		tdif = t[j + k - 1]
	dif = max(dif, tdif)
print(dif + soma)


(n, k) = map(int, input().split())
a = [int(s) for s in input().split()]
t = [int(s) for s in input().split()]
s = 0
s2 = 0
for i in range(n):
	if i < k and t[i] == 0:
		s += a[i]
	elif t[i] != 0:
		s2 += a[i]
ms = s
for i in range(k, n):
	if t[i] == 0:
		s += a[i]
	if t[i - k] == 0:
		s -= a[i - k]
	if s > ms:
		ms = s
print(ms + s2)


(n, k) = map(int, input().split())
theorems = [int(i) for i in input().split()]
wake = [int(i) for i in input().split()]
acu = 0
for i in range(n):
	if wake[i] == 1:
		acu += theorems[i]
	elif i < k:
		acu += theorems[i]
ans = acu
j = k
ans = acu
for i in range(n - k):
	if wake[i] == 0:
		acu -= theorems[i]
	if wake[j] == 0:
		acu += theorems[j]
	ans = max(ans, acu)
	j += 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
c = list(map(int, input().split()))
s = 0
ss = 0
for i in range(n):
	if c[i] == 1:
		ss += a[i]
for i in range(k):
	if c[i] == 0:
		s += a[i]
m = s
for i in range(n - k):
	if c[i] == 0:
		s -= a[i]
	if c[i + k] == 0:
		s += a[i + k]
	m = max(m, s)
print(ss + m)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
flag = True
firstIndex = -1
res = 0
for i in range(n):
	if t[i] == 1:
		res += a[i]
	elif flag and t[i] == 0:
		flag = False
		firstIndex = i
maxyRes = 0
maxy = 0
for i in range(firstIndex, firstIndex + k):
	if i == n:
		break
	if t[i] == 0:
		maxy += a[i]
if maxy > maxyRes:
	maxyRes = maxy
for i in range(firstIndex, n - k):
	if t[i] == 0:
		maxy -= a[i]
	if t[i + k] == 0:
		maxy += a[i + k]
	if maxy > maxyRes:
		maxyRes = maxy
print(res + maxyRes)


(n, k) = map(int, input().split())
aa = list(map(int, input().split()))
t = list(map(int, input().split()))
answer1 = 0
for i in range(0, n):
	if t[i] == 1:
		answer1 += aa[i]
		aa[i] = 0
answer0 = 0
sum = 0
for i in range(0, n):
	sum += aa[i]
	if i >= k:
		sum -= aa[i - k]
	answer0 = max(answer0, sum)
print(answer1 + answer0)


import math
from decimal import *
(n, k) = map(int, input().split())
ans = 0
cnt = 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pref = [0] * n
for i in range(n):
	if b[i]:
		ans += a[i]
	else:
		cnt += a[i]
	pref[i] = cnt
mx = pref[k - 1]
for i in range(k, n):
	mx = max(mx, pref[i] - pref[i - k])
ans += mx
print(ans)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [i for i in a]
d = [i for i in a]
for i in range(len(b)):
	if b[i] == 1:
		c[i] = 0
	else:
		d[i] = 0
for i in range(1, len(c)):
	c[i] += c[i - 1]
g = [i for i in c]
for i in range(k, len(c)):
	g[i] -= c[i - k]
print(sum(d) + max(g))


(n, k) = list(map(int, input().split(' ')))
value = list(map(int, input().split(' ')))
condition = list(map(int, input().split(' ')))
sum = 0
for x in range(n):
	if condition[x] == 1:
		sum += value[x]
		value[x] = 0
sum2 = 0
for x in range(k):
	if condition[x] == 0:
		sum2 += value[x]
temp = sum2
for x in range(0, n - k):
	temp = temp - value[x] + value[x + k]
	if temp > sum2:
		sum2 = temp
print(sum2 + sum)


(n, k) = map(int, input().split())
a_vec = list(map(int, input().split()))
t_vec = list(map(int, input().split()))
sleep_vec = [0] * n
a_sum = 0
a_zero_sum = 0
i_zero = 0
for i in range(n):
	if i >= k and t_vec[i - k] == 0:
		i_zero -= a_vec[i - k]
	if t_vec[i] == 1:
		a_sum += a_vec[i]
	else:
		i_zero += a_vec[i]
		a_zero_sum = max(a_zero_sum, i_zero)
print(a_sum + a_zero_sum)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
total = sum([a[i] for i in range(n) if t[i]])
maxSleep = slider = sum([a[i] for i in range(k) if not t[i]])
for i in range(k, n):
	if not t[i]:
		slider += a[i]
	if not t[i - k]:
		slider -= a[i - k]
	maxSleep = max(slider, maxSleep)
print(maxSleep + total)


(n, k) = [int(i) for i in input().split()]
ai = [int(i) for i in input().split()]
ti = [int(i) for i in input().split()]
gi = [ai[i] * (1 - ti[i]) for i in range(n)]
current_gain = sum(gi[:k])
max_gain = current_gain
for i in range(1, n - k + 1):
	current_gain = current_gain - gi[i - 1] + gi[i + k - 1]
	max_gain = max(max_gain, current_gain)
print(sum(map(lambda x, y: x * y, ai, ti)) + max_gain)


from itertools import *
R = lambda : map(int, input().split())
(n, k) = R()
a = list(zip(R(), R()))
print(sum((x * y for (x, y) in a)) + max(accumulate((x - x * y - u + u * v for ((u, v), (x, y)) in zip([(0, 0)] * k + a, a)))))


(N, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
S = 0
for i in range(len(B)):
	if B[i] == 1:
		S += A[i]
T = 0
V = 0
flag = 0
for i in range(N - k + 1):
	for t in range(i, i + k):
		if B[t] == 0:
			for j in range(i, i + k):
				if B[j] != 1:
					T += A[j]
			m = i
			V = T
			flag += 1
			break
	if flag != 0:
		break
if V != 0:
	for i in range(m + 1, N - k + 1):
		if B[i - 1] == 0:
			T -= A[i - 1]
		if B[i + k - 1] == 0:
			T += A[i + k - 1]
		V = max(V, T)
print(S + V)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [0] * n
for i in range(k):
	dp[0] += 0 if t[i] == 1 else a[i]
for i in range(1, n - k + 1):
	dp[i] = dp[i - 1] + (0 if t[i + k - 1] == 1 else a[i + k - 1]) - (0 if t[i - 1] == 1 else a[i - 1])
val = 0
for i in range(n):
	if t[i] == 1:
		val += a[i]
print(val + max(dp))


(n, k) = tuple(map(int, input().split(' ')))
theorems = list(map(int, input().split(' ')))
dreams = list(map(int, input().split(' ')))
a = [x if dreams[i] else 0 for (i, x) in enumerate(theorems)]
dreams = a
(cumsum1, cumsum2) = ([0] * n, [0] * n)
for (i, x) in enumerate(theorems):
	cumsum1[i] = cumsum1[i - 1] + x if i > 0 else x
for (i, x) in enumerate(dreams):
	cumsum2[i] = cumsum2[i - 1] + x if i > 0 else x
cumsum1.append(0)
cumsum2.append(0)
res = 0
s = sum(dreams)
for i in range(k - 1, n):
	res = max(res, s - (cumsum2[i] - cumsum2[i - k]) + (cumsum1[i] - cumsum1[i - k]))
print(res)


(n, k) = [int(x) for x in input().split()[:2]]
an = [int(x) for x in input().split()[:n]]
tn = [int(x) for x in input().split()[:n]]
first = 0
for i in range(k):
	first += an[i]
for i in range(k, n):
	first += an[i] * tn[i]
ans = first
for i in range(1, n - k + 1):
	new = i + k - 1
	last = i - 1
	if tn[last] == 0:
		first -= an[last]
	if tn[new] == 0:
		first += an[new]
	ans = max(first, ans)
print(ans)


options = list(map(int, input().split(' ')))
n = options[0]
awake = options[1]
lecture = [0] + list(map(int, input().split(' ')))
sleep = [0] + list(map(int, input().split(' ')))
sum_l1 = [0]
sum_l2 = [0]
output = 0
max_n = 0
for minute in range(1, n + 1):
	sum_l1.append(sum_l1[minute - 1] + lecture[minute] * sleep[minute])
	sum_l2.append(sum_l2[minute - 1] + lecture[minute])
max_v = 0
for minute in range(1, n - awake + 2):
	v = sum_l1[minute - 1] + sum_l2[minute + awake - 1] - sum_l2[minute - 1] + sum_l1[n] - sum_l1[minute + awake - 1]
	max_v = max(v, max_v)
print(max_v)


from collections import deque
(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
s = []
t = deque(s)
s1 = 0
z = 0
s2 = 0
for i in range(n):
	if l2[i] == 1:
		s2 = s2 + l1[i]
for i in range(n):
	if l2[i] == 1:
		t.append(0)
		z += 0
	else:
		z = z + l1[i]
		t.append(l1[i])
	if len(t) > k:
		r = t.popleft()
		z = z - r
	s1 = max(s1, z)
print(s1 + s2)


(n, k) = [int(x) for x in input().split()]
teoremas = [int(x) for x in input().split()]
acordado = input().split()
teoremasAc = [0] * (n + 1)
teoremasWakeAc = [0] * (n + 1)
for i in range(1, n + 1):
	teoremasAc[i] = teoremas[i - 1] + teoremasAc[i - 1]
	teoremasWakeAc[i] = teoremasWakeAc[i - 1]
	if acordado[i - 1] == '1':
		teoremasWakeAc[i] += teoremas[i - 1]
total = 0
for i in range(k, n + 1):
	a = teoremasAc[i] - teoremasAc[i - k]
	b = teoremasWakeAc[i] - teoremasWakeAc[i - k]
	dif = a - b
	total = max(total, dif)
print(total + teoremasWakeAc[n])


(n, k) = map(int, input().split())
teorems = list(map(int, input().split()))
res = list(map(int, input().split()))
sum_ = 0
for i in range(n):
	if res[i] == 1:
		sum_ += teorems[i]
sum1 = 0
for i in range(k):
	sum1 += teorems[i]
current = 0
answer = 0
double_counted = 0
for i in range(current, current + k):
	if res[i] == 1:
		double_counted += teorems[i]
ind = 0
for i in range(n - k + 1):
	current_sum = 0
	current_sum = sum_ + sum1 - double_counted
	if current_sum > answer:
		ind = current
		answer = current_sum
	current += 1
	if i == n - k:
		break
	sum1 -= teorems[current - 1]
	sum1 += teorems[current + k - 1]
	if res[current - 1] == 1:
		double_counted -= teorems[current - 1]
	if res[current + k - 1] == 1:
		double_counted += teorems[current + k - 1]
print(answer)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	t = [int(x) for x in input().split()]
	mx = 0
	for i in range(n):
		if i < k:
			mx += a[i]
		else:
			mx += a[i] * t[i]
	xx = mx
	for i in range(n):
		if i + k >= n:
			break
		xx -= a[i]
		xx += a[i] * t[i]
		xx += a[i + k]
		xx -= a[i + k] * t[i + k]
		mx = max(xx, mx)
	print(mx)

def __starting_point():
	main()
__starting_point()


from itertools import accumulate
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
overall = 0
for (i, s) in enumerate(t):
	if s == 1:
		overall += a[i]
		a[i] = 0
pr = list(accumulate(a))
magic = 0
for i in range(n - 1, -1, -1):
	start = 0 if i - k < 0 else pr[i - k]
	magic = max(magic, pr[i] - start)
print(overall + magic)


(x, y) = map(int, input().split())
z = list(map(int, input().split()))
r = list(map(int, input().split()))
ans = [sum(z[0:y])]
for i in range(1, len(z) - y + 1):
	ans.append(ans[-1] - z[i - 1] + z[i + y - 1])
temp = [0]
for i in range(len(z)):
	if r[i] == 0:
		temp.append(temp[-1])
	else:
		temp.append(temp[-1] + z[i])
ram = []
for i in range(len(ans)):
	ram.append(ans[i] + (temp[-1] - temp[i + y]) + temp[i])
print(max(ram))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		op = list(In())
		(su, total) = (0, 0)
		ans = 0
		temp_sum = 0
		for x in range(n):
			if x < k:
				su += l[x]
				if op[x] == 1:
					temp_sum += l[x]
			if op[x] == 1:
				total += l[x]
		ans = max(ans, total - temp_sum + su)
		for x in range(k, n):
			su -= l[x - k]
			if op[x - k] == 1:
				temp_sum -= l[x - k]
			if op[x] == 1:
				temp_sum += l[x]
			su += l[x]
			ans = max(ans, total - temp_sum + su)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
max_ = sum([x for (i, x) in enumerate(t[:k]) if a[i] == 0])
imax = 0
current = max_
for i in range(1, n - k + 1):
	if a[i - 1] == 0:
		current -= t[i - 1]
	if a[i + k - 1] == 0:
		current += t[i + k - 1]
	if current > max_:
		max_ = current
		imax = i
for i in range(len(a)):
	if imax <= i < imax + k:
		a[i] = 1
print(sum([x for (i, x) in enumerate(t) if a[i] == 1]))


(n, k) = map(int, input().split())
thm_count = list(map(int, input().split()))
is_awake = list(map(int, input().split()))
real_prefixes = []
real_sum = 0
no_sleep_prefixes = []
no_sleep_sum = 0
for i in range(n):
	if is_awake[i] == 1:
		real_sum += thm_count[i]
	real_prefixes.append(real_sum)
	no_sleep_sum += thm_count[i]
	no_sleep_prefixes.append(no_sleep_sum)
max_thms = -1
for i in range(n - k + 1):
	res = real_prefixes[i - 1] if i > 0 else 0
	res += no_sleep_prefixes[i + k - 1]
	res -= no_sleep_prefixes[i - 1] if i > 0 else 0
	res += real_prefixes[n - 1]
	res -= real_prefixes[i + k - 1]
	max_thms = max(max_thms, res)
print(max_thms)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sumx = 0
sum1 = 0
s = 0
for i in range(n):
	if b[i] == 1:
		sum1 += a[i]
for i in range(k):
	if b[i] == 0:
		sumx += a[i]
s = sumx + sum1
for i in range(k, n):
	if b[i - k] == 0:
		sumx -= a[i - k]
	if b[i] == 0:
		sumx += a[i]
	if sumx + sum1 > s:
		s = sumx + sum1
print(s)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
e = deque([])
f = deque([])
s = 0
m = 0
se = 0
for i in range(n):
	if e and f[0] <= i - k:
		se -= e[0]
		f.popleft()
		e.popleft()
	s += t[i] * a[i]
	if t[i] == 0:
		e.append(a[i])
		se += a[i]
		f.append(i)
		if len(e) > k:
			se -= e[0]
			e.popleft()
			f.popleft()
		m = max(m, se)
print(s + m)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
psA = [0 for i in range(n + 1)]
psT = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	psA[i] = psA[i - 1] + A[i - 1]
	psT[i] = psT[i - 1] + A[i - 1] * T[i - 1]
ans = 0
for j in range(1, n - k + 2):
	ans = max(ans, psT[j - 1] + psA[j + k - 1] - psA[j - 1] + psT[n] - psT[j + k - 1])
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s = sum([a[i] * t[i] for i in range(n)])
s += sum([a[i] * (1 - t[i]) for i in range(k)])
ans = s
for i in range(n - k):
	s -= a[i] * (1 - t[i])
	s += a[i + k] * (1 - t[i + k])
	ans = max(ans, s)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(n):
	if b[i]:
		b[i] = 0
		s += a[i]
	else:
		b[i] = a[i]
	b[i] += b[i - 1] if i != 0 else 0
mx = 0
for j in range(n - k + 1):
	mx = max(mx, b[j + k - 1] - b[j - 1] if j != 0 else b[j + k - 1])
print(mx + s)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
(n, k) = R()
(*a,) = R()
(*b,) = R()
v = []
p = 0
for i in range(n):
	if not b[i]:
		v += (a[i],)
	else:
		v += (0,)
ans = sum(v[:k])
p = ans
for i in range(k, n):
	p += v[i] - v[i - k]
	ans = max(ans, p)
print(sum([a[i] for i in range(n) if b[i]]) + ans)


def main():
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	T = list(map(int, input().split()))
	S = [0 if T[i] else A[i] for i in range(n)]
	all_summ = [sum(S[0:0 + k])] + [0] * (n - k)
	for i in range(k, n):
		all_summ[i - k + 1] = all_summ[i - k] + S[i] - S[i - k]
	print(sum([A[i] for i in range(n) if T[i]]) + max(all_summ))
main()


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(y):
	if b[i] == 0:
		s += a[i]
k = s
for i in range(y, x):
	if b[i] == 0:
		s += a[i]
	if b[i - y] == 0:
		s -= a[i - y]
	k = max(k, s)
for i in range(x):
	if b[i] == 1:
		k += a[i]
print(k)


def get_list_by_str(st):
	data = list()
	w = ''
	for e in st:
		if e == ' ':
			data.append(int(w))
			w = ''
		else:
			w += e
	data.append(int(w))
	return data
(n, k) = input().split()
n = int(n)
k = int(k)
a = get_list_by_str(input())
t = get_list_by_str(input())
c = list()
for i in range(0, n):
	tt = 1
	if t[i] == 1:
		tt = 0
	c.append(a[i] * tt)
cur = 0
for i in range(0, k):
	cur += c[i]
mi = 0
mx = cur
for i in range(k, n):
	cur += c[i]
	cur -= c[i - k]
	if cur > mx:
		mx = cur
		mi = i - k + 1
teorems = 0
for i in range(0, mi):
	teorems += a[i] * t[i]
for i in range(mi, mi + k):
	teorems += a[i]
for i in range(mi + k, n):
	teorems += a[i] * t[i]
print(teorems)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
x = 0
summ = 0
maxx = 0
for i in range(n):
	summ += a[i] * t[i]
for i in range(k):
	if not t[i]:
		x += a[i]
maxx = max(maxx, x)
for i in range(n - k):
	x += a[i + k] * (1 - t[i + k])
	x -= a[i] * (1 - t[i])
	if x > maxx:
		maxx = x
print(summ + maxx)


(n, k) = (int(i) for i in input().split())
th = [int(i) for i in input().split()]
bh = [int(i) for i in input().split()]
tot = 0
for (i, v) in enumerate(th):
	if bh[i]:
		tot += v
tots = []
tt = 0
for i in range(k):
	if bh[i] == 0:
		tt += th[i]
tots.append(tt)
for i in range(1, n - k + 1):
	if bh[i - 1] == 0:
		tt -= th[i - 1]
	if bh[i + k - 1] == 0:
		tt += th[i + k - 1]
	tots.append(tt)
print(tot + max(tots))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s = [0] * (n - k + 1)
res = 0
for i in range(n):
	if t[i] == 1:
		res += a[i]
for i in range(k):
	if t[i] == 0:
		s[0] += a[i]
for i in range(1, n - k + 1):
	w = 0
	if t[i - 1] == 0:
		w -= a[i - 1]
	if t[i + k - 1] == 0:
		w += a[i + k - 1]
	s[i] = s[i - 1] + w
print(res + max(s))


a = list(map(int, input().split()))
n = a[0]
k = a[1]
a = list(map(int, input().split()))
t = list(map(int, input().split()))
nt = 0
for i in range(len(a)):
	if t[i] == 1:
		nt += a[i]
s = 0
for i in range(k):
	if t[i] == 0:
		s += a[i]
hel = s
for i in range(k, len(a), 1):
	if t[i] == 0 and t[i - k] == 0:
		hel = hel + a[i] - a[i - k]
	elif t[i] == 1 and t[i - k] == 0:
		hel = hel - a[i - k]
	elif t[i] == 0 and t[i - k] == 1:
		hel = hel + a[i]
	if hel > s:
		s = hel
print(nt + s)


inputint = lambda : list(map(int, input().split()))
(n, k) = inputint()
tp = inputint()
td = inputint()
temp = sum([tp[j] * (1 - td[j]) for j in range(k)])
maxint = temp
for i in range(1, n - k + 1):
	temp = temp - tp[i - 1] * (1 - td[i - 1]) + tp[i + k - 1] * (1 - td[i + k - 1])
	maxint = temp if temp > maxint else maxint
print(sum([tp[i] * td[i] for i in range(n)]) + maxint)


def main():
	(n, k) = (int(x) for x in input().split())
	array = [int(x) for x in input().split()]
	time = [int(x) for x in input().split()]
	s = 0
	temp = []
	for i in range(k):
		if time[i] == 0:
			s += array[i]
	temp.append(s)
	for i in range(1, n - k + 1):
		if time[i + k - 1] == 0:
			s += array[i + k - 1]
		if time[i - 1] == 0:
			s = s - array[i - 1]
		temp.append(s)
	s = 0
	for i in range(n):
		if time[i]:
			s += array[i]
	print(s + max(temp))
main()


(n, k) = input().split(' ')
n = int(n)
k = int(k)
T = input().split(' ')
W = input().split(' ')
TT = [int(t) for t in T]
WW = [int(w) for w in W]
ans = 0
for i in range(n):
	if WW[i] == 1:
		ans += TT[i]
		TT[i] = 0
ansW = sum(TT[:k])
temp = ansW
i = 1
while i <= n - k:
	temp = temp - TT[i - 1] + TT[i + k - 1]
	if temp > ansW:
		ansW = temp
	i += 1
print(ans + ansW)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
theorems = list(map(int, input().split()))
sleep = list(map(int, input().split()))
tsum = []
ts = 0
sleepsum = []
slsum = 0
for i in range(n):
	ts += theorems[i]
	tsum.append(ts)
	if sleep[i] == 1:
		slsum += theorems[i]
	sleepsum.append(slsum)
maxdiff = 0
maxdiff = tsum[k - 1] - sleepsum[k - 1]
for i in range(1, n - k + 1):
	diff = tsum[i + k - 1] - tsum[i - 1] - (sleepsum[i + k - 1] - sleepsum[i - 1])
	maxdiff = max(maxdiff, diff)
print(slsum + maxdiff)


import sys
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
if k > n:
	print(sum(l))
	sys.exit()
base = 0
for i in range(n):
	if t[i] == 1:
		base += l[i]
		l[i] = 0
max1 = 0
cur = sum(l[:k])
max1 = cur
for i in range(k, n):
	cur -= l[i - k]
	cur += l[i]
	max1 = max(cur, max1)
print(max1 + base)


I = lambda : map(int, input().split())
(n, k) = I()
li = list(I())
le = list(I())
d = {}
su = 0
for i in range(n):
	su += li[i] * le[i]
i = 0
suu = su
t = 0
for i in range(k):
	if le[i] == 0:
		suu += li[i]
ans = suu
for i in range(k, n):
	if le[i] == 0:
		suu += li[i]
	if le[i - k] == 0:
		suu -= li[i - k]
	ans = max(ans, suu)
print(ans)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
inc = [0] * n
base = 0
for i in range(n):
	if t[i] == 0:
		inc[i] = a[i]
	else:
		base += a[i]
val = 0
val = sum(inc[:k])
ans = val
for i in range(n - k):
	ans = max(ans, val - inc[i] + inc[i + k])
	val += inc[i + k] - inc[i]
print(base + ans)


lecture_and_tech_time = list(map(int, input().split(' ')))
theorem_count = list(map(int, input().split(' ')))
sleep_or_not = list(map(int, input().split(' ')))
lecture_time = lecture_and_tech_time[0]
tech_time = lecture_and_tech_time[1]
total_theorem_count_original = 0
extra_theorem_count = 0
for (idx, s_or_n) in enumerate(sleep_or_not):
	if s_or_n == 0:
		continue
	else:
		total_theorem_count_original += theorem_count[idx]
		theorem_count[idx] = 0
max_extra_theorem_count = 0
for (idx, theorem) in enumerate(theorem_count):
	if len(theorem_count) > idx - tech_time >= 0:
		prev_val = theorem_count[idx - tech_time]
		max_extra_theorem_count = max_extra_theorem_count - prev_val + theorem
	else:
		prev_val = -1
		max_extra_theorem_count += theorem
	extra_theorem_count = max_extra_theorem_count if max_extra_theorem_count > extra_theorem_count else extra_theorem_count
print(total_theorem_count_original + extra_theorem_count)


(n, k) = list(map(int, input().split()))
a_list = list(map(int, input().split()))
t_list = list(map(int, input().split()))
lst_sum = [0] * k
overall = 0
for i in range(n):
	lst_sum.append(lst_sum[i + k - 1])
	if t_list[i] == 1:
		overall += a_list[i]
	else:
		lst_sum[i + k] += a_list[i]
max_sum = 0
for i in range(k, n + k):
	if max_sum < lst_sum[i] - lst_sum[i - k]:
		max_sum = lst_sum[i] - lst_sum[i - k]
print(max_sum + overall)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = sum([a[i] for i in range(n) if t[i] == 1])
z = [i for i in range(n) if t[i] == 0]
ln = len(z)
d = 0
now = 0
(left, right) = (0, -1)
for i in range(2 * ln):
	if right + 1 < ln and z[right + 1] - z[left] < k:
		right += 1
		now += a[z[right]]
		d = max(d, now)
	else:
		now -= a[z[left]]
		left += 1
print(ans + d)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mask = list(map(int, input().split()))
result = sum((a[i] if mask[i] == 1 else 0 for i in range(n)))
h = [a[i] if mask[i] == 0 else 0 for i in range(len(a))]
best_awake = sum(h[:k])
curr = best_awake
for j in range(k, n):
	curr += h[j]
	curr -= h[j - k]
	best_awake = max(best_awake, curr)
print(result + best_awake)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
(n, k) = map(int, input().split())
t = list(map(int, input().split()))
s = list(map(int, input().split()))
m = 0
p = 0
for i in range(k):
	if s[i] == 0:
		m += t[i]
c = m
for i in range(1, n - k + 1):
	if s[i - 1] == 0:
		c -= t[i - 1]
	if s[i + k - 1] == 0:
		c += t[i + k - 1]
	m = max(m, c)
for i in range(n):
	if s[i] == 1:
		p += t[i]
print(p + m)


(n, k) = map(int, input().split())
(a, t) = (list(map(int, input().split())), list(map(int, input().split())))
c = sum((a[i] * (1 - t[i]) for i in range(k)))
v = c
for i in range(k, n):
	c += a[i] * (1 - t[i]) - a[i - k] * (1 - t[i - k])
	v = max(v, c)
print(sum((ai * ti for (ai, ti) in zip(a, t))) + v)


(n, k) = map(int, input().split())
th = list(map(int, input().split()))
mi = list(map(int, input().split()))
a = [0] * n
for i in range(n):
	a[i] = mi[i] * th[i]
su = sum(th[:k]) + sum(a[k:])
m = su
for i in range(n - k):
	su -= th[i]
	su += th[i + k]
	su += a[i]
	su -= a[i + k]
	m = max(su, m)
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
total = 0
if t[0] == 1:
	total += a[0]
	a[0] = 0
for i in range(1, n):
	aux = a[i]
	if t[i] == 1:
		total += a[i]
		aux = 0
	a[i] = aux + a[i - 1]
max_gain = 0
if t[0] == 0:
	max_gain = a[0 + k - 1]
for i in range(1, n):
	if t[i] == 0:
		r = i + k - 1
		if r >= n:
			r = n - 1
		gain = a[r] - a[i - 1]
		if gain > max_gain:
			max_gain = gain
print(max_gain + total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ps = [0] * (n - k + 1)
p = [0] * (n - k + 1)
s = 0
for i in range(n):
	s += a[i] * t[i]
for i in range(k):
	ps[0] += a[i]
	p[0] += a[i] * t[i]
for i in range(1, n - k + 1):
	ps[i] = ps[i - 1] - a[i - 1] + a[i + k - 1]
	p[i] = p[i - 1] - a[i - 1] * t[i - 1] + a[i + k - 1] * t[i + k - 1]
ans = 0
for i in range(n - k + 1):
	c = s + ps[i] - p[i]
	ans = max(ans, c)
print(ans)


num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
k = int(num_input[1])
arr_theorem = input()
arr_theorem = arr_theorem.split(' ')
for i in range(0, len(arr_theorem)):
	arr_theorem[i] = int(arr_theorem[i])
arr_sleep = input()
arr_sleep = arr_sleep.split(' ')
for i in range(0, len(arr_sleep)):
	arr_sleep[i] = int(arr_sleep[i])
max_sleep = 0
max = 0
for i in range(0, k):
	if arr_sleep[i] == 0:
		max_sleep += arr_theorem[i]
		max = max_sleep
for i in range(1, n - (k - 1)):
	if arr_sleep[i - 1] == 0:
		max_sleep -= arr_theorem[i - 1]
	if arr_sleep[i + k - 1] == 0:
		max_sleep += arr_theorem[i + k - 1]
	if max_sleep > max:
		max = max_sleep
normal_sleep = 0
for i in range(0, n):
	if arr_sleep[i] == 1:
		normal_sleep += arr_theorem[i]
print(max + normal_sleep)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
b = []
s = 0
for i in range(0, n):
	if t[i] == 1:
		s += a[i]
		b.append(0)
	else:
		b.append(a[i])
c = sum(b[0:k])
m = c
for i in range(k, n):
	c += b[i] - b[i - k]
	m = max(m, c)
print(s + m)


(n, k) = [int(x) for x in input().split()]
ns = [int(x) for x in input().split()]
ts = [int(x) for x in input().split()]
lft = 0
rgt = k - 1
ans = 0
for (i, x) in enumerate(ns):
	if i < k or ts[i]:
		ans += x
a = ans
while rgt < n - 1:
	if not ts[lft]:
		a -= ns[lft]
	if not ts[rgt + 1]:
		a += ns[rgt + 1]
	lft += 1
	rgt += 1
	ans = max(a, ans)
print(ans)


I = lambda : map(int, input().split())
(n, k) = I()
(A, T) = (list(I()), list(I()))
(B, C) = ([a * (1 - t) for (a, t) in zip(A, T)], [0] * (n - k + 1))
C[0] = sum(B[:k])
for i in range(n - k):
	C[i + 1] = C[i] - B[i] + B[i + k]
print(sum((a * t for (a, t) in zip(A, T))) + max(C))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(n):
	if b[i] == 1:
		s += a[i]
sum = s
maxi = 0
s = 0
i = 0
j = 0
while j < k:
	if b[j] == 0:
		s = s + a[j]
	j += 1
maxi = sum + s
j -= 1
while j + 1 < n:
	if b[i] == 0:
		s -= a[i]
	i += 1
	j += 1
	if b[j] == 0:
		s += a[j]
	maxi = max(maxi, s + sum)
print(maxi)


from sys import stdin as sin
(n, k) = map(int, sin.readline().split())
a = list(map(int, sin.readline().split(' ')))
x = list(map(int, sin.readline().split(' ')))
te = [] + a
te[0] = te[0] * x[0]
re = [] + a
re[-1] *= x[-1]
for i in range(n - 2, -1, -1):
	re[i] = re[i + 1] + re[i] * x[i]
	te[n - i - 1] = te[n - i - 2] + te[n - i - 1] * x[n - i - 1]
s = sum(a[0:k])
if n == k:
	print(s)
else:
	m = max(s + re[k], sum(a[n - k:n]) + te[n - k - 1])
	for i in range(1, n - k):
		s += a[i + k - 1] - a[i - 1]
		m = max(m, te[i - 1] + s + re[i + k])
	print(m)


(n, k) = map(int, input().split())
lst = []
for x in input().split():
	lst.append(int(x))
array = []
for x in input().split():
	array.append(int(x))
mass1 = [0]
for x in range(n):
	mass1.append(mass1[-1] + lst[x])
mass2 = [0]
for x in range(n):
	mass2.append(mass2[-1] + lst[x] * array[x])
ans = 0
for x in range(1, n - k + 2):
	ans = max(ans, mass2[x - 1] + (mass1[x + k - 1] - mass1[x - 1]) + (mass2[-1] - mass2[x + k - 1]))
print(ans)


a = input()
b = input()
c = input()
a = a.split(' ')
b = b.split(' ')
c = c.split(' ')
for i in range(len(a)):
	a[i] = int(a[i])
for i in range(len(b)):
	b[i] = int(b[i])
for i in range(len(c)):
	c[i] = int(c[i])

def blower():
	d = []
	s = 0
	x = 0
	for i in range(a[1]):
		if c[i] == 0:
			s += b[i]
	d += [s]
	for i in range(a[1], a[0]):
		if c[i - a[1]] == 0:
			s -= b[i - a[1]]
		if c[i] == 0:
			s += b[i]
		d += [s]
	for i in range(a[0]):
		if c[i] == 1:
			x += b[i]
	print(x + max(d))
blower()


(n, k) = map(int, input().split())
lec = [int(i) for i in input().split()]
sleep = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
	if sleep[i]:
		cnt += lec[i]
		lec[i] = 0
last = sum(lec[0:k])
Max = last
for i in range(k, n):
	cur = last + lec[i] - lec[i - k]
	if cur > Max:
		Max = cur
	last = cur
print(Max + cnt)


(n, k) = map(int, input().split())
thm = list(map(int, input().split()))
t = list(map(int, input().split()))
total = 0
for i in range(n):
	if t[i] == 1:
		total += thm[i]
M = 0
for i in range(k):
	if t[i] == 0:
		M += thm[i]
max_thm = M
i = 1
while i <= n - k:
	if t[i - 1] == 0:
		M -= thm[i - 1]
	if t[i + k - 1] == 0:
		M += thm[i + k - 1]
	if M > max_thm:
		max_thm = M
	i += 1
print(max_thm + total)


rd = lambda : map(int, input().split())
(n, k) = rd()
a = [0] + list(rd())
t = [0] + list(rd())
s = 0
(p, m) = (0, 0)
for i in range(n + 1):
	(x, y) = (a[i], t[i])
	s += x * y
	p += x * (1 - y)
	p -= a[max(0, i - k)] * (1 - t[max(0, i - k)])
	m = max(p, m)
print(s + m)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = [0] * n
if b[0] == 0:
	s[0] = a[0]
su = 0
for i in range(n):
	if b[i] == 1:
		su += a[i]
for i in range(1, n):
	if b[i] == 0:
		s[i] = a[i]
max_init_sum = init_sum = sum(s[:m])
k = m
for i in range(k, n):
	init_sum = init_sum - s[i - k] + s[i]
	max_init_sum = max(max_init_sum, init_sum)
print(max_init_sum + su)


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
t = [int(s) for s in input().split()]
base = 0
for i in range(n):
	base += a[i] * t[i]
gain0 = 0
for i in range(k):
	if t[i] == 0:
		gain0 += a[i]
maxgain = gain0
prevgain = gain0
for i in range(1, n - k + 1):
	gain = prevgain
	if t[i - 1] == 0:
		gain -= a[i - 1]
	if t[i + k - 1] == 0:
		gain += a[i + k - 1]
	if gain > maxgain:
		maxgain = gain
	prevgain = gain
print(base + maxgain)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
su = 0
for i in range(n):
	if t[i] == 1:
		su += a[i]
		a[i] = 0
s = 0
for i in range(k):
	s += a[i]
m = s
j = 0
for i in range(k, n):
	s = s + a[i] - a[j]
	j += 1
	m = max(m, s)
print(su + m)


(n, k) = [int(i) for i in input().split()]
cnt = [int(i) for i in input().split()]
sleep = [int(i) for i in input().split()]
pref = [0 for i in range(n + 1)]
ans = 0
for i in range(n):
	if sleep[i]:
		ans += cnt[i]
		cnt[i] = 0
	pref[i + 1] = pref[i] + cnt[i]
ma = 0
for i in range(n - k + 1):
	ma = max(ma, pref[i + k] - pref[i])
print(ma + ans)


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	(n, k) = mi()
	a = li()
	b = li()
	x = [0] * (n + 1)
	y = [0] * (n + 1)
	for i in range(1, n + 1):
		x[i] = x[i - 1] + a[i - 1]
		y[i] = y[i - 1]
		if b[i - 1] == 1:
			y[i] += a[i - 1]
	ans = 0
	for i in range(n - k + 1):
		s = 0
		s += x[i + k] - x[i]
		s += y[n] - y[k + i]
		s += y[i]
		ans = max(s, ans)
	print(ans)
solve()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
ans = 0
ans1 = []
for i in range(k):
	c.append(a[i])
	if b[i] == 0:
		ans += a[i]
m = 0
for i in range(k, n):
	ans1.append(ans)
	c[m] = 0
	if b[m] == 0:
		ans -= a[m]
	m += 1
	c.append(a[i])
	if b[i] == 0:
		ans += a[i]
ans1.append(ans)
ans2 = 0
for i in range(n):
	if b[i] == 1:
		ans2 += a[i]
x = max(ans1)
print(x + ans2)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = list(map(int, input().split()))
sum1 = 0
dic = {}
for i in range(n):
	if s[i] != 0:
		sum1 = sum1 + l[i]
	else:
		dic[i] = l[i]
if len(dic) != 0:
	l2 = list(dic.values())
	s2 = list(dic.keys())
	m = len(l2)
	sum2 = l2[0]
	strt = 0
	end = 1
	max = 0
	while strt < m and end < m:
		if s2[end] - s2[strt] <= k - 1:
			sum2 = sum2 + l2[end]
			end = end + 1
		else:
			if sum2 > max:
				max = sum2
			sum2 = sum2 - l2[strt]
			strt = strt + 1
	if sum2 > max:
		max = sum2
	print(sum1 + max)
else:
	print(sum1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
cond = list(map(int, input().split()))
awake = 0
for i in range(n):
	if cond[i]:
		awake += arr[i]
		arr[i] = 0
sleep = sum(arr[:k])
flag = sleep
for i in range(k, n):
	sleep = sleep + arr[i] - arr[i - k]
	flag = max(flag, sleep)
print(flag + awake)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
max = 0
lis = []
max = 0
for i in range(0, k):
	if t[i] == 0:
		max += a[i]
lis.append(max)
m = max
for i in range(1, n - k + 1):
	if t[i - 1] == 0:
		max = max - a[i - 1]
	if t[i + k - 1] == 0:
		max = max + a[i + k - 1]
	if m < max:
		m = max
	lis.append(max)
sum = 0
for i in range(0, n):
	if t[i] == 1:
		sum += a[i]
print(sum + m)


from sys import stdin, stdout
inp = lambda : (int(i) for i in stdin.readline().split())
(n, k) = inp()
a = list(inp())
t = list(inp())
z = []
b = []
ans = 0
for i in range(n):
	if t[i] == 0:
		z.append(a[i])
	else:
		z.append(0)
sum = sum(z[:k])
b.append(sum)
for i in range(n - k):
	sum += z[i + k] - z[i]
	b.append(sum)
for i in range(n):
	if t[i] != 0:
		ans += a[i]
stdout.write(str(ans + max(b)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [0] * n
s = 0
for j in range(n):
	if t[j] == 1:
		s += a[j]
		a[j] = 0
co = 0
m = 0
l = sum(a[co:co + k])
for j in range(n - k + 1):
	co = j
	ss = 0
	m = max(m, l + s)
	if co + k < n:
		l -= a[co]
		l += a[co + k]
print(m)


import bisect
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = 0
(ax, tx) = ([], [])
for i in range(n):
	if t[i] == 1:
		ans = ans + a[i]
	else:
		ax.append(a[i])
		tx.append(i)
m = 0
for i in range(1, len(ax)):
	ax[i] += ax[i - 1]
for i in range(len(ax)):
	j = bisect.bisect_right(tx, tx[i] + k - 1) - 1
	if i > 0:
		m = max(m, ax[j] - ax[i - 1])
	else:
		m = max(m, ax[j])
ans = ans + m
print(ans)


import sys, math, queue, bisect
MOD = 998244353
sys.setrecursionlimit(1000000)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
w = list(map(int, input().split()))
x = [0 for i in range(n + 1)]
y = [0 for i in range(n + 1)]
z = [0 for i in range(n + 1)]
for i in reversed(range(n)):
	if w[i]:
		z[i] = z[i + 1] + a[i]
	else:
		z[i] = z[i + 1]
for i in range(n):
	y[i] = y[i - 1] + a[i]
	if w[i]:
		x[i] = x[i - 1] + a[i]
	else:
		x[i] = x[i - 1]
ans = 0
for i in range(k - 1, n):
	ans = max(ans, x[i - k] + y[i] - y[i - k] + z[i + 1])
print(ans)


import operator
import functools

def sumproduct(*lists):
	return sum((functools.reduce(operator.mul, data) for data in zip(*lists)))
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
b = [0] * n
for i in range(n):
	if not t[i]:
		b[i] = a[i]
s = sumproduct(a, t)
d = sum(b[:k])
maxD = d
for i in range(n - k):
	d += b[i + k] - b[i]
	if d > maxD:
		maxD = d
print(s + maxD)


(n, k) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	if m[i] == 1:
		ans += t[i]
		t[i] = 0
maxim = 0
for i in range(k):
	maxim += t[i]
a = [maxim]
for i in range(k, n):
	maxim += t[i] - t[i - k]
	a.append(maxim)
print(ans + max(a))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ad = []
temp = 0
c1 = 0
for i in range(n):
	if t[i] == 0:
		temp += a[i]
	else:
		c1 += a[i]
	ad.append(temp)
ans = ad[k - 1]
for i in range(1, n - k + 1):
	ans = max(ans, ad[i + k - 1] - ad[i - 1])
print(ans + c1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
num = 0
for i in range(n):
	if t[i] == 1:
		num += a[i]
rec = 0
for i in range(k):
	if t[i] == 0:
		rec += a[i]
tmp = rec
for i in range(k, n):
	if t[i - k] == 0:
		tmp -= a[i - k]
	if t[i] == 0:
		tmp += a[i]
	rec = max(rec, tmp)
print(num + rec)


def main():
	(n, k) = map(int, input().split())
	a = [int(c) for c in input().split()]
	t = [int(c) for c in input().split()]
	diff = 0
	i = 0
	s = 0
	ii = jj = 0
	while i < n:
		ii += a[i]
		if i - k >= 0:
			ii -= a[i - k]
		if t[i] == 1:
			s += a[i]
			jj += a[i]
		if i - k >= 0 and t[i - k] == 1:
			jj -= a[i - k]
		diff = max(diff, ii - jj)
		i += 1
	print(s + diff)
main()


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
t = [int(q) for q in input().split()]
total_sum = 0
for i in range(n):
	if t[i] == 1:
		total_sum += a[i]
		a[i] = 0
summ = 0
for i in range(k):
	summ += a[i]
maxx = summ
for i in range(k, n):
	summ += a[i]
	summ -= a[i - k]
	maxx = max(summ, maxx)
print(maxx + total_sum)


def read_data():
	(n, m) = map(int, list(input().strip().split()))
	a = list(map(int, list(input().strip().split())))
	b = list(map(int, list(input().strip().split())))
	return (n, m, a, b)

def solve():
	val = 0
	for i in range(n):
		if b[i] == 1:
			val += a[i]
	for i in range(k):
		if b[i] == 0:
			val += a[i]
	i = k
	max = val
	while i < n:
		if b[i - k] == 0:
			val -= a[i - k]
		if b[i] == 0:
			val += a[i]
		if val > max:
			max = val
		i += 1
	return max
(n, k, a, b) = read_data()
print(solve())


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
sum1 = 0
count = 0
for i in range(n):
	if t[i] == 1:
		sum1 += a[i]
	elif t[i] == 0 and i < k:
		count += a[i]
ans = count
i = 1
while i < n - k + 1:
	if t[i - 1] == 0:
		count -= a[i - 1]
	if t[i + k - 1] == 0:
		count += a[i + k - 1]
	ans = max(count, ans)
	i += 1
print(ans + sum1)


(n, k) = map(int, input().split())
theorems = list(map(int, input().split()))
behavior = list(map(int, input().split()))
total = sum(theorems)
local = sum(theorems[:k])
natural = 0
for i in range(k, n):
	if behavior[i] == 1:
		natural += theorems[i]
m = local + natural
for i in range(n - k):
	if behavior[i] == 0:
		natural -= theorems[i]
	if behavior[k + i] == 0:
		local += theorems[k + i]
	m = max(m, local + natural)
print(m)


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
lec = 0
for i in range(n):
	if t[i] == 1:
		lec += arr[i]
		t[i] = 0
	else:
		t[i] = 1
temp_lec = sum([arr[i] * t[i] for i in range(k)])
max_lec = temp_lec
for i in range(k, n):
	temp_lec += arr[i] * t[i] - arr[i - k] * t[i - k]
	max_lec = max(max_lec, temp_lec)
print(lec + max_lec)


def Slove():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	res_max = 0
	pr = [0] * n
	for i in range(n):
		if i:
			pr[i] += pr[i - 1]
		if t[i] == 0:
			pr[i] += a[i]
		else:
			res_max += a[i]
	tmp_max = 0
	for i in range(k - 1, n):
		if i == k - 1:
			tmp_max = max(tmp_max, pr[i])
		else:
			tmp_max = max(tmp_max, pr[i] - pr[i - k])
	return res_max + tmp_max
print(Slove())


def calculate_prefix_sum(a, t):
	s = [0]
	for (a_, t_) in zip(a, t):
		if not t_:
			s += [s[-1] + a_]
		else:
			s += [s[-1]]
	return s

def calculate_sum_on_range(s, a, b):
	assert a < b
	return s[min(b, len(s) - 1)] - s[a]

def calculate_sums(a, t, k):
	psum = calculate_prefix_sum(a, t)
	s = []
	for i in range(len(a)):
		s.append(calculate_sum_on_range(psum, i, i + k))
	return s

def calculate_max(a, t, k):
	s = calculate_sums(a, t, k)
	ms = max(s)
	return ms

def calculate_answer(a, t, k):
	ms = calculate_max(a, t, k)
	s = 0
	for (a_, t_) in zip(a, t):
		if t_:
			s += a_
	return ms + s
r = lambda : list(map(int, input().split()))
(_, k) = r()
print(calculate_answer(r(), r(), k))


(n, k) = [int(x) for x in input().split(' ')]
arr_a = [int(x) for x in input().split(' ')]
arr_t = [int(x) for x in input().split(' ')]
sum_wake = 0
for i in range(n):
	if arr_t[i] == 1:
		sum_wake += arr_a[i]
		arr_a[i] = 0
largest_sum = sum(arr_a[0:k])
current_sum = largest_sum
for j in range(k, n):
	current_sum += arr_a[j] - arr_a[j - k]
	if current_sum > largest_sum:
		largest_sum = current_sum
print(largest_sum + sum_wake)


x = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ac1 = []
ac2 = []
for i in range(len(l1)):
	if i == 0:
		ac1.append(l1[i])
		if l2[i] == 1:
			ac2.append(l1[i])
		else:
			ac2.append(0)
	else:
		ac1.append(l1[i] + ac1[i - 1])
		if l2[i] == 1:
			ac2.append(l1[i] + ac2[i - 1])
		else:
			ac2.append(ac2[i - 1])
result = ac1[x[1] - 1] - ac2[x[1] - 1]
for l in range(x[0] - x[1]):
	r = l + x[1]
	sum1 = ac1[r] - ac1[l]
	sum2 = ac2[r] - ac2[l]
	if sum1 - sum2 > result:
		result = sum1 - sum2
print(result + ac2[-1])


line = [int(e) for e in input().split(' ')]
(n, k) = (line[0], line[1])
theorems = [int(e) for e in input().split(' ')]
sleep = [int(e) for e in input().split(' ')]
maxScore = 0
currentScore = 0
for e in range(k):
	if sleep[e] == 0:
		currentScore += theorems[e]
maxScore = currentScore
for j in range(1, n - k + 1):
	if sleep[j - 1] == 0:
		currentScore -= theorems[j - 1]
	if sleep[j + k - 1] == 0:
		currentScore += theorems[j + k - 1]
	maxScore = max(maxScore, currentScore)
for j in range(n):
	if sleep[j] == 1:
		maxScore += theorems[j]
print(maxScore)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
Sums = []
if t[0] == 0:
	Sums.append(a[0])
else:
	Sums.append(0)
for i in range(1, n):
	if t[i] == 0:
		Sums.append(Sums[i - 1] + a[i])
	else:
		Sums.append(Sums[i - 1])
index = 0
Max = 0
minus = 0
for i in range(k - 1, n):
	if Sums[i] - minus > Max:
		Max = Sums[i] - minus
		index = i
	minus = Sums[i - k + 1]
for i in range(index - k + 1, index + 1):
	t[i] = 1
Sum = 0
for i in range(len(a)):
	if t[i] == 1:
		Sum += a[i]
print(Sum)


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = []
(cnt, ans, a) = (0, 0, 0)
(l, r) = (0, min(k, n))
for i in range(min(k, n)):
	if d[i] == 0:
		cnt += s[i]
for i in range(n):
	if d[i] == 1:
		ans += s[i]
a = cnt
while r < n:
	if d[r] == 0:
		cnt += s[r]
	if d[l] == 0:
		cnt -= s[l]
	a = max(a, cnt)
	l += 1
	r += 1
print(ans + a)


a = list(map(int, input().split()))
t = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(a[0]):
	if b[i]:
		res += t[i]
		t[i] = 0
sl = k = sum(t[:a[1]])
for i in range(1, a[0] - a[1] + 1):
	k = k - t[i - 1] + t[i + a[1] - 1]
	if k > sl:
		sl = k
print(str(sl + res))


(n, k) = list(map(int, input().split()))
al = list(map(int, input().split()))
tl = list(map(int, input().split()))
rl = [1 - tl[i] for i in range(n)]
rs = sum([al[i] * tl[i] for i in range(n)])
bl = [0] * (n - k + 1)
bl[0] = sum([al[i] * rl[i] for i in range(k)])
for i in range(1, n - k + 1):
	bl[i] = bl[i - 1] + al[i + k - 1] * rl[i + k - 1] - al[i - 1] * rl[i - 1]
print(max(bl) + rs)


(n, k) = map(int, input().split())
theorems = list(map(int, input().split()))
sleep = list(map(int, input().split()))
max_ = 0
res = 0
sum_ = 0
for i in range(n):
	if sleep[i] == 1:
		res += theorems[i]
		theorems[i] = 0
	sum_ += theorems[i]
	j = i - k
	if j >= 0:
		sum_ -= theorems[j]
	max_ = max(max_, sum_)
print(res + max_)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
t = list(map(int, input().split()))
res = 0
for i in range(n):
	if t[i] == 1:
		res += arr[i]
		arr[i] = 0
dp = [0] * n
dp[0] = arr[0]
count = 1
i = 1
while i < n:
	if count < k:
		count += 1
		dp[i] = dp[i - 1] + arr[i]
	else:
		dp[i] = dp[i - 1] + arr[i] - arr[i - k]
	i += 1
print(max(dp) + res)


n_k = input().split()
n = int(n_k[0])
k = int(n_k[1])
aulas = input().split()
estado = input().split()
soma_aulas = []
soma_acordado = []
s_aulas = 0
s_acordado = 0
for i in range(n):
	s_aulas += int(aulas[i])
	soma_aulas.append(s_aulas)
	if estado[i] == '1':
		s_acordado += int(aulas[i])
	soma_acordado.append(s_acordado)
saida = 0
for j in range(n - k + 1):
	a = j + k - 1
	if j == 0:
		s1 = soma_aulas[a]
		s2 = soma_acordado[a]
	else:
		s1 = soma_aulas[a] - soma_aulas[j - 1]
		s2 = soma_acordado[a] - soma_acordado[j - 1]
	s = s1 - s2
	if s > saida:
		saida = s
print(soma_acordado[n - 1] + saida)


(n, t) = map(int, input().split())
theory = list(map(int, input().split()))
awake = list(map(int, input().split()))
have = 0
for i in range(0, n):
	if awake[i] == 1:
		have += theory[i]
		theory[i] = 0
sum_theory = []
tmp = 0
for i in range(0, n):
	tmp += theory[i]
	sum_theory.append(tmp)
tmp = sum_theory[t - 1]
for i in range(0, n - t):
	tmp = max(tmp, sum_theory[i + t] - sum_theory[i])
print(have + tmp)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
teo = 0
for i in range(0, n):
	if t[i] == 1:
		teo += a[i]
help = 0
temp = 0
for j in range(0, k):
	if t[j] == 0:
		temp += a[j]
help = temp
for i in range(0, n - k):
	if t[i] == 0:
		temp -= a[i]
	if t[i + k] == 0:
		temp += a[i + k]
	if temp > help:
		help = temp
print(teo + help)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
temp = list(map(int, input().split()))
ans = 0
for i in range(n):
	if temp[i] == 1:
		ans += arr[i]
final = []
cnt = 0
for i in range(k):
	if temp[i] == 0:
		cnt += arr[i]
final.append(cnt)
(low, high) = (1, k)
while high < n:
	if temp[low - 1] == 0:
		cnt -= arr[low - 1]
	if temp[high] == 0:
		cnt += arr[high]
	final.append(cnt)
	low += 1
	high += 1
print(ans + max(final))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
l = 0
s = 0
for i in range(n):
	if t[i] or i < k:
		s += a[i]
ans = s
r = k - 1
while r < n:
	if t[l] == 0:
		s -= a[l]
	if r + 1 < n and t[r + 1] == 0:
		s += a[r + 1]
	l += 1
	r += 1
	ans = max(ans, s)
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
add = 0
out = 0
s = [0]
for r in range(n):
	if t[r] == 0:
		s.append(s[r] + a[r])
	else:
		s.append(s[r])
if t[-1] == 0 and a[-1] > s[-2]:
	add = a[-1]
for i in range(n):
	if i <= n - k + 1:
		try:
			add = max(add, s[i + k] - s[i])
		except:
			add = max(add, s[-1] - s[i])
	if t[i] == 1:
		out += a[i]
print(out + add)


R = lambda : map(int, input().split())
(n, k) = R()
(a, b) = (list(R()), list(R()))
org = [ai * bi for (ai, bi) in zip(a, b)]
for i in range(1, n):
	org[i] += org[i - 1]
for i in range(1, n):
	a[i] += a[i - 1]
add = 0
for i in range(0, n - k + 1):
	add = max(add, a[i + k - 1] - (a[i - 1] if i else 0) - (org[i + k - 1] - (org[i - 1] if i else 0)))
print(org[n - 1] + add)


(n, k) = list(map(int, input().split()))
inp = list(map(int, input().split()))
inp2 = list(map(int, input().split()))
s = 0
for i in range(n):
	s += inp[i] * inp2[i]
for i in range(n):
	if inp2[i] == 1:
		inp[i] = 0
sum1 = 0
for i in range(k):
	sum1 += inp[i]
max1 = sum1
for i in range(k, n):
	sum1 += inp[i]
	sum1 -= inp[i - k]
	if sum1 > max1:
		max1 = sum1
print(max1 + s)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [0 for i in range(n + 1)]
total = 0
for i in range(1, n + 1):
	total += t[i - 1] * a[i - 1]
	dp[i] = dp[i - 1] + a[i - 1] * (1 - t[i - 1])
ans = 0
for i in range(1, n - k + 2):
	ans = max(ans, total + dp[i + k - 1] - dp[i - 1])
print(ans)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
s = input().split()
ai = []
for i in s:
	ai.append(int(i))
s = input().split()
ti = []
tti = []
coords = []
for i in s:
	ti.append(int(i))
	tti.append(int(i))
	if int(i) == 0:
		coords.append(len(ti) - 1)
s = 0
for i in range(len(ti)):
	s += ti[i] * ai[i]
sum = s
for q in range(k):
	if ti[q] == 0:
		sum += ai[q]
max = sum
for i in range(1, n):
	if i + k <= n:
		if ti[i - 1] == 0:
			sum -= ai[i - 1]
		if ti[i + k - 1] == 0:
			sum += ai[i + k - 1]
		if sum > max:
			max = sum
print(max)


e = input().split()
n = int(e[0])
k = int(e[1])
teoremas = input().split()
teoremas = [int(x) for x in teoremas]
mishka = input().split()
mishka = [int(x) for x in mishka]
soma_t = []
soma_m = []
cont_t = 0
cont_m = 0
resposta = 0
for i in range(n):
	if mishka[i] == 1:
		cont_m += teoremas[i]
	soma_m.append(cont_m)
	cont_t += teoremas[i]
	soma_t.append(cont_t)
for x in range(n - k + 1):
	y = x + k - 1
	if x == 0:
		aux_t = soma_t[y]
		aux_m = soma_m[y]
	else:
		aux_t = soma_t[y] - soma_t[x - 1]
		aux_m = soma_m[y] - soma_m[x - 1]
	resposta = max(resposta, aux_t - aux_m)
print(soma_m[n - 1] + resposta)


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
awake = list(map(int, input().split()))
best = 0
curr = 0
for i in range(n):
	if not awake[i]:
		curr += v[i]
	if i >= k and (not awake[i - k]):
		curr -= v[i - k]
	best = max(best, curr)
res = sum((awake[i] * v[i] for i in range(n))) + best
print(res)


from collections import Counter

def main():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	print(solve(n, k, a, t))

def solve(n, k, a, t):
	minsum = sum((ai for (ai, ti) in zip(a, t) if ti == 1))
	inc = sum((ai for (ai, ti) in zip(a[:k], t[:k]) if ti == 0))
	best_inc = inc
	for i in range(1, n - k + 1):
		if t[i - 1] == 0:
			inc -= a[i - 1]
		if t[i + k - 1] == 0:
			inc += a[i + k - 1]
		if inc > best_inc:
			best_inc = inc
	return minsum + best_inc
main()


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import operator

def main():
	z = ''
	d = defaultdict()
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	initial_sum = sum(a[:k])
	all_sum = [0]
	for i in range(n):
		if t[i] == 1:
			all_sum.append(all_sum[-1] + a[i])
		else:
			all_sum.append(all_sum[-1])
	m = all_sum[-1]
	for i in range(n - k + 1):
		t_sum = all_sum[i] + initial_sum + all_sum[-1] - all_sum[i + k]
		m = max(m, t_sum)
		if i + k < n:
			initial_sum = initial_sum - a[i] + a[i + k]
	print(m)
main()


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
t = list(map(int, input().strip().split()))
cnt = 0
maxtemp = 0
l = 0
r = l + k - 1
for i in range(l, r + 1):
	if t[i] == 1:
		cnt += a[i]
	else:
		maxtemp += a[i]
temp = maxtemp
for i in range(1, n - k + 1):
	if t[l] == 0:
		temp -= a[l]
	l += 1
	r += 1
	if t[r] == 0:
		temp += a[r]
	else:
		cnt += a[r]
	maxtemp = max(maxtemp, temp)
print(cnt + maxtemp)


def solve(k, theorems, awake):
	theorems_a = [0 for i in range(len(theorems))]
	copy_theorems = [i for i in theorems]
	for i in range(1, len(theorems)):
		theorems[i] += theorems[i - 1]
	if awake[0] == 1:
		theorems_a[0] = copy_theorems[0]
	for i in range(1, len(theorems)):
		theorems_a[i] = theorems_a[i - 1]
		if awake[i] == 1:
			theorems_a[i] += copy_theorems[i]
	theorems.insert(0, 0)
	theorems_a.insert(0, 0)
	result = 0
	for i in range(len(theorems) - k):
		r = i + k
		sum_t = theorems[r] - theorems[i]
		sum_a = theorems_a[r] - theorems_a[i]
		result = max(result, sum_t - sum_a)
	return theorems_a[-1] + result
(d, k) = list(map(int, input().split()))
theorems = list(map(int, input().split()))
awake = list(map(int, input().split()))
print(solve(k, theorems, awake))


(n, k) = [int(x) for x in input().split()]
lis = [int(x) for x in input().split()]
taken = [int(x) for x in input().split()]
best_start_index = -1
best_start = 0
current_start = 0
current_total_with = 0
current_total_without = 0
for i in range(k):
	current_total_with += lis[i]
	if taken[i] == 1:
		current_total_without += lis[i]
best_start_index = 0
best_start = current_total_with - current_total_without
for i in range(1, n - k + 1):
	current_total_with -= lis[i - 1]
	current_total_with += lis[i + k - 1]
	if taken[i - 1] == 1:
		current_total_without -= lis[i - 1]
	if taken[i + k - 1]:
		current_total_without += lis[i + k - 1]
	if best_start < current_total_with - current_total_without:
		best_start = current_total_with - current_total_without
		best_start_index = i
i = 0
total = 0
while i < n:
	if i >= best_start_index and i < best_start_index + k:
		total += lis[i]
	elif taken[i]:
		total += lis[i]
	i += 1
print(total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lec = 0
su = 0
for i in range(n):
	if b[i] == 1:
		lec += a[i]
		a[i] = 0
for i in range(1, n):
	a[i] += a[i - 1]
for i in range(n):
	if i - k < 0:
		su = max(su, a[i])
	else:
		su = max(su, a[i] - a[i - k])
print(lec + su)


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	(n, k) = GIS()
	ts = LGIS()
	bs = LGIS()
	mg = gain = sum((t if b == 0 else 0 for (t, b) in zip(ts[:k], bs[:k])))
	r = k
	while r < n:
		if not bs[r]:
			gain += ts[r]
		if not bs[r - k]:
			gain -= ts[r - k]
		mg = max(mg, gain)
		r += 1
	print(mg + sum((t if b else 0 for (t, b) in zip(ts, bs))))
main()


(n, k) = map(int, input().split())
tes = list(map(int, input().split()))
ts = list(map(int, input().split()))
tems = []
ms = 0
(s, o) = (0, 0)
for i in range(n):
	if ts[i] == 1:
		o += tes[i]
		(tes[i], a) = (0, 0)
	else:
		a = tes[i]
	s += a
	tems += [a]
	if i >= k:
		s -= tems[i - k]
		ms = max(ms, s)
	elif i == k - 1:
		ms = max(ms, s)
print(o + ms)


(n, k) = map(int, input().split())
mas = list(map(int, input().split()))
lizt = list(map(int, input().split()))
res = 0
for i in range(n):
	if lizt[i] == 1:
		res += mas[i]
q = 0
for i in range(k):
	if lizt[i] == 0:
		q += mas[i]
a = q
for i in range(1, n - k + 1):
	e = a
	if lizt[i - 1] == 0:
		e -= mas[i - 1]
	if lizt[i + k - 1] == 0:
		e += mas[i + k - 1]
	if q < e:
		q = e
	a = e
print(res + q)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = []
ans = 0
for i in range(n):
	if b[i] == 0:
		c.append(a[i])
	else:
		c.append(0)
sum = sum(c[:k])
d.append(sum)
for i in range(n - k):
	sum += c[i + k] - c[i]
	d.append(sum)
for i in range(n):
	if b[i] != 0:
		ans += a[i]
print(ans + max(d))


(n, k) = map(int, input().split())
weights = [int(x) for x in input().split()]
awaketime = [int(x) for x in input().split()]
asleeptime = [1 - x for x in awaketime]
awaketheorems = [weights[i] * awaketime[i] for i in range(n)]
asleeptheorems = [weights[i] * asleeptime[i] for i in range(n)]
awaketotal = sum(awaketheorems)
asleeptotal = sum(asleeptheorems[0:k])
bestasleeptotal = asleeptotal
for i in range(n - k):
	asleeptotal -= asleeptheorems[i]
	asleeptotal += asleeptheorems[i + k]
	bestasleeptotal = max(asleeptotal, bestasleeptotal)
print(awaketotal + bestasleeptotal)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
s = 0
maxx = 0
for i in range(k):
	if t[i] == 0:
		s += l[i]
maxx = s
for i in range(n - k):
	if t[i] == 0:
		s -= l[i]
	if t[k + i] == 0:
		s += l[k + i]
	if s > maxx:
		maxx = s
count = 0
for i in range(n):
	if t[i] == 1:
		count += l[i]
count += maxx
print(count)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
Total = 0
for i in range(n):
	Total += a[i] * t[i]
slow = 0
fast = 0
Max = 0
L = []
while fast != n:
	if fast - slow < k:
		Max += a[fast] * (1 - t[fast])
		L.append(Max)
		fast += 1
	else:
		Max -= a[slow] * (1 - t[slow])
		Max += a[fast] * (1 - t[fast])
		slow += 1
		fast += 1
		L.append(Max)
print(max(L) + Total)


import sys

def solve(io):
	N = io.readInt()
	K = io.readInt()
	A = io.readIntArray(N)
	T = io.readIntArray(N)
	total = 0
	cs = [0] * (N + 1)
	for i in range(0, N):
		if T[i] == 0:
			cs[i + 1] = cs[i] + A[i]
		else:
			total += A[i]
			cs[i + 1] = cs[i]
	best = 0
	for i in range(0, N - K + 1):
		best = max(best, cs[i + K] - cs[i])
	io.println(total + best)

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readStringArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readString())
		return arr

	def readIntArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readInt())
		return arr

	def readFloatArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readFloat())
		return arr

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def prints(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.prints(s)
		self.prints('\n')

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tot_lecture = 0
for i in range(n):
	if B[i] == 1:
		tot_lecture += A[i]
for i in range(k):
	if B[i] == 0:
		tot_lecture += A[i]
curr_sum = tot_lecture
for i in range(1, n - k + 1):
	if B[i - 1] == 0:
		curr_sum -= A[i - 1]
	if B[i + k - 1] == 0:
		curr_sum += A[i + k - 1]
	if curr_sum > tot_lecture:
		tot_lecture = curr_sum
print(tot_lecture)


(n, k) = map(int, input().split())
lectures = list(map(int, input().split()))
sleeping = list(map(int, input().split()))
dp_ok = [0] * (n - k + 1)
dp_magic = [0] * (n - k + 1)
(s1, s2) = (0, 0)
for i in range(k):
	s1 += lectures[i] * sleeping[i]
	s2 += lectures[i]
dp_ok[0] = s1
dp_magic[0] = s2
(max_diff, max_index) = (dp_magic[0] - dp_ok[0], 0)
for i in range(k, n):
	j = i - k
	dp_ok[j + 1] = dp_ok[j] - lectures[j] * sleeping[j] + lectures[i] * sleeping[i]
	dp_magic[j + 1] = dp_magic[j] - lectures[j] + lectures[i]
	diff = dp_magic[j + 1] - dp_ok[j + 1]
	if diff > max_diff:
		max_diff = diff
		max_index = j + 1
res = 0
for i in range(n):
	if i >= max_index and i < max_index + k:
		res += lectures[i]
	else:
		res += lectures[i] * sleeping[i]
print(res)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
start = 0
end = m - 1
total = 0
total = sum([a[i] for i in range(n) if b[i] == 1])
for i in range(start, end + 1):
	total += a[i] if b[i] == 0 else 0
max_ans = total
while end < n - 1:
	end += 1
	start += 1
	total -= a[start - 1] if b[start - 1] == 0 else 0
	total += a[end] if b[end] == 0 else 0
	max_ans = max(max_ans, total)
print(max_ans)


(n, k) = map(int, input().strip().split())
L = list(map(int, input().strip().split()))
P = list(map(int, input().strip().split()))
L = [0] + L
P = [0] + P
total = 0
for i in range(1, n + 1):
	total += L[i] * P[i]
cum = 0
for i in range(1, k + 1):
	if not P[i]:
		cum += L[i]
maxcum = cum
for i in range(1, n - k + 1):
	cum += L[i + k] * (1 - P[i + k])
	cum -= L[i] * (1 - P[i])
	maxcum = max(maxcum, cum)
print(maxcum + total)


(n, k) = [int(x) for x in input().split()]
teoremas = [int(x) for x in input().split()]
acordado = [int(x) for x in input().split()]
acumuladoWake = [0] * (n + 1)
acumuladoSleep = [0] * (n + 1)
for i in range(1, n + 1):
	acumuladoWake[i] = teoremas[i - 1] + acumuladoWake[i - 1]
	if acordado[i - 1] == 1:
		acumuladoSleep[i] = teoremas[i - 1] + acumuladoSleep[i - 1]
	else:
		acumuladoSleep[i] = 0 + acumuladoSleep[i - 1]
windowSum = 0
maxSum = 0
for i in range(1, n - k + 2):
	wake = acumuladoWake[i + k - 1] - acumuladoWake[i - 1]
	sleep = acumuladoSleep[i + k - 1] - acumuladoSleep[i - 1]
	windowSum = wake - sleep
	maxSum = max(windowSum, maxSum)
print(maxSum + acumuladoSleep[n])


inp = list(map(int, input().split()))
(n, k) = (inp[0], inp[1])
a = list(map(int, input().split()))
t = list(map(int, input().split()))
l = len(t)
sum = 0
for i in range(l):
	sum = sum + a[i] * t[i]
	t[i] = 1 - t[i]
	a[i] = a[i] * t[i]
x = 0
for i in range(0, k):
	x = x + a[i]
mx = x
for i in range(1, n - k + 1, 1):
	x = x - a[i - 1] + a[i + k - 1]
	if x > mx:
		mx = x
sum = sum + mx
print(sum)


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	temp_sum = 0
	lec_sum = 0
	for i in range(0, n):
		if t[i]:
			lec_sum += a[i]
			a[i] = 0
	prefix_sum = [a[0]]
	for i in range(1, n):
		prefix_sum.append(prefix_sum[-1] + a[i])
	i = 0
	j = k
	temp_sum = prefix_sum[k - 1]
	while j < n:
		temp_sum = max(temp_sum, prefix_sum[j] - prefix_sum[i])
		i += 1
		j += 1
	print(lec_sum + temp_sum)
main()


I = lambda : map(int, input().split())
(n, k) = I()
a = list(I())
t = list(I())
aa = [0] * (n + 1)
ta = [0] * (n + 1)
for i in range(1, n + 1):
	aa[i] = aa[i - 1] + a[i - 1]
	if t[i - 1] == 1:
		ta[i] = ta[i - 1] + a[i - 1]
	else:
		ta[i] = ta[i - 1]
result = 0
for i in range(n - k + 2):
	r = i + k - 1
	sum1 = aa[r] - aa[i - 1]
	sum2 = ta[r] - ta[i - 1]
	result = max(result, sum1 - sum2)
print(ta[n] + result)


def start_index(items, l):
	current_sub = sum(items[0:l])
	max_sub = current_sub
	currentt_index = 0
	max_index = 0
	for i in items[l:]:
		current_sub += i
		current_sub -= items[currentt_index]
		currentt_index += 1
		if current_sub > max_sub:
			max_sub = current_sub
			max_index = currentt_index
	return max_index
(n, k) = (int(i) for i in input().split())
lecture_times = [int(i) for i in input().split()]
sleep_times = [int(i) for i in input().split()]
zero_times = [lecture_times[i] * (1 - sleep_times[i]) for i in range(n)]
k_index = start_index(zero_times, k)
for i in range(k):
	sleep_times[i + k_index] = 1
sum = 0
for i in range(n):
	if sleep_times[i] != 0:
		sum += lecture_times[i]
print(sum)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
maxSoma = 0
for i in range(n):
	maxSoma += a[i] * t[i]
	if t[i] == 0 and i < k:
		maxSoma += a[i]
(soma, i, j) = (maxSoma, 0, k - 1)
while j < n - 1:
	if t[j + 1] == 0:
		soma += a[j + 1]
	if t[i] == 0:
		soma -= a[i]
	if soma > maxSoma:
		maxSoma = soma
	i += 1
	j += 1
print(maxSoma)


words = []
for word in input().split():
	words.append(word)
n = int(words[0])
k = int(words[1])
v = []
for word in input().split():
	v.append(int(word))
s = []
for word in input().split():
	s.append(int(word))
addition = 0
maxAddition = 0
for i in range(k):
	if s[i] == 0:
		addition += v[i]
		maxAddition = max(maxAddition, addition)
for i in range(k, n):
	if s[i - k] == 0:
		addition -= v[i - k]
	if s[i] == 0:
		addition += v[i]
	maxAddition = max(maxAddition, addition)
sum = 0
for i in range(n):
	if s[i] == 1:
		sum += v[i]
print(sum + maxAddition)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s = [0] * n
pre = [0] * n
suf = [0] * n
s[0] = a[0]
pre[0] = a[0] if t[0] > 0 else 0
for i in range(1, n):
	s[i] = s[i - 1] + a[i]
	pre[i] = pre[i - 1] + (a[i] if t[i] > 0 else 0)
suf[n - 1] = a[n - 1] if t[n - 1] > 0 else 0
for i in range(n - 2, -1, -1):
	suf[i] = suf[i + 1] + (a[i] if t[i] > 0 else 0)
ans = 0
for i in range(n - k + 1):
	w = s[i + k - 1] - (s[i - 1] if i > 0 else 0)
	w += pre[i - 1] if i > 0 else 0
	w += suf[i + k] if i + k < n else 0
	ans = max(ans, w)
print(ans)


import sys
input = lambda : list(map(int, sys.stdin.readline().split()))

def main():
	(n, k) = input()
	a = [0] + input()
	t = input()
	s = [0] * (n + 1)
	s[1] = a[1]
	ss = [0] * (n + 1)
	ss[1] = t[0] * a[1]
	for i in range(2, n + 1):
		s[i] = a[i] + s[i - 1]
		ss[i] = t[i - 1] * a[i] + ss[i - 1]
	r = 0
	for i in range(1, n - k + 2):
		r = max(r, s[i + k - 1] - s[i - 1] + ss[i - 1] + ss[-1] - ss[i + k - 1])
	print(r)
main()


(n, k) = tuple(input().split())
(n, k) = (int(n), int(k))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
res = 0
for i in range(n):
	res += t[i] * a[i]
	if t[i]:
		a[i] = 0
s = sum(a[:k])
cands = [s]
for i in range(k, n):
	s = s - a[i - k] + a[i]
	cands.append(s)
print(res + max(cands))


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, k) = mp()
	l = li()
	x = li()
	ans = 0
	s = 0
	for i in range(n):
		if x[i] == 1:
			ans += l[i]
			l[i] = 0
	for i in range(k):
		s += l[i]
	now = s
	for i in range(k, n):
		s -= l[i - k]
		s += l[i]
		now = max(now, s)
	pr(ans + now)
for _ in range(1):
	solve()


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = []
sums = 0
need = 0
for i in range(n):
	if l1[i] == 1:
		need += l[i]
for i in range(m):
	if i < m:
		if l1[i] == 0:
			l2 += [l[i]]
			sums += l[i]
		else:
			l2 += [0]
maxs = sums
for j in range(i + 1, n):
	sums -= l2[0]
	del l2[0]
	if l1[j] == 0:
		l2 += [l[j]]
		sums += l[j]
	else:
		l2 += [0]
	maxs = max(maxs, sums)
print(maxs + need)


from functools import reduce
(n, k) = [int(i) for i in input().split()]
a = list(map(int, input().split()))
t = list(map(int, input().split()))
(res, cur, suf) = [0, 0, reduce(lambda x, y: a[y] * t[y] + x, [int(i) for i in range(n)]) + a[0] * t[0]]
for i in range(n):
	cur += a[i]
	suf -= a[i] * t[i]
	if i - k >= 0:
		cur -= a[i - k] * (1 - t[i - k])
	res = max(res, cur + suf)
print(res)


import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
th = get_array()
state = get_array()
curr_benefit = 0
max_benefit = 0
for i in range(k):
	if state[i] == 0:
		curr_benefit += th[i]
max_benefit = max(max_benefit, curr_benefit)
index1 = 0
index2 = k - 1
i = 1
j = k
m = 0
while j < n:
	if state[j] == 0:
		curr_benefit += th[j]
	if state[m] == 0:
		curr_benefit -= th[m]
	if curr_benefit > max_benefit:
		index1 = i
		index2 = j
		max_benefit = curr_benefit
	i += 1
	j += 1
	m += 1
total = 0
for i in range(n):
	if index1 <= i <= index2:
		total += th[i]
	elif state[i] == 1:
		total += th[i]
print(total)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		(n, k) = invr()
		a = inlt()
		b = inlt()
		extra = 0
		for i in range(k):
			if not b[i]:
				extra += a[i]
		ans = 0
		temp = 0
		for i in range(n):
			if b[i]:
				ans += a[i]
			if not b[i]:
				temp += a[i]
			if i > k - 1 and (not b[i - k]):
				temp -= a[i - k]
			extra = max(extra, temp)
		print(ans + extra)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
articles = list(map(int, input().split()))
behavior = list(map(int, input().split()))
cumulative = [0]
total = 0
for i in range(n):
	if behavior[i] == 1:
		total += articles[i]
		articles[i] = 0
for j in range(1, n + 1):
	cumulative.append(articles[j - 1] + cumulative[j - 1])
temp = 0
for m in range(n, k - 1, -1):
	if temp < cumulative[m] - cumulative[m - k]:
		temp = cumulative[m] - cumulative[m - k]
print(temp + total)


import sys
import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
suma = [0] * n
sumat = [0] * n
suma[0] = a[0]
sumat[0] = a[0] * t[0]
for i in range(1, n):
	suma[i] = suma[i - 1] + a[i]
for i in range(1, n):
	sumat[i] = sumat[i - 1] + a[i] * t[i]
m = -10
for i in range(n - k + 1):
	if i > 0:
		m = max(m, sumat[i - 1] + sumat[n - 1] - sumat[i + k - 1] + suma[i + k - 1] - suma[i - 1])
	else:
		m = max(m, sumat[n - 1] - sumat[i + k - 1] + suma[i + k - 1])
print(m)


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
summ = 0
for i in range(len(a)):
	if b[i] == 1:
		summ += a[i]
		a[i] = 0
for i in range(1, len(a)):
	a[i] += a[i - 1]
a.insert(0, 0)
maxx = 0
for i in range(d, len(a)):
	maxx = max(maxx, a[i] - a[i - d])
print(maxx + summ)


import sys
from itertools import accumulate
input = lambda : sys.stdin.readline().strip('\r\n')
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
res = 0
for i in range(n):
	if t[i]:
		res += a[i]
		a[i] = 0
a = [0] + list(accumulate(a))
ans = res
for i in range(1, n - k + 2):
	ans = max(ans, res + a[i + k - 1] - a[i - 1])
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
b = [0]
total = 0
for i in range(n):
	if t[i] == 0:
		b.append(a[i] + b[i])
	else:
		b.append(b[i])
		total += a[i]
maxi = -1
for i in range(1, n - k + 2):
	maxi = max(maxi, b[i + k - 1] - b[i - 1])
print(total + maxi)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
(total, count) = (0, 0)
extra = 0
for i in range(n):
	if t[i] == 1:
		total += a[i]
for i in range(n):
	count += 1
	if t[i] == 0:
		extra += a[i]
	if count == k:
		break
largest = extra
for j in range(i + 1, n):
	if t[j - k] == 0:
		extra -= a[j - k]
	if t[j] == 0:
		extra += a[j]
	largest = max(largest, extra)
print(largest + total)


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	asleep = list(map(int, input().split()))
	sm = mx = res = 0
	for i in range(n):
		if asleep[i] == 1:
			res += arr[i]
		if i < k:
			if asleep[i] == 0:
				sm += arr[i]
		else:
			if asleep[i] == 0:
				sm += arr[i]
			if asleep[i - k] == 0:
				sm -= arr[i - k]
		mx = max(mx, sm)
	print(mx + res)
main()


(n, k) = list(map(int, input().split()))
aa = list(map(int, input().split()))
tt = list(map(int, input().split()))
rr = [a * (1 - t) for (a, t) in zip(aa, tt)]
v1 = sum(rr[0:k])
f = [v1]
fst = rr[0]
if k > 1:
	for (fst, lst) in zip(rr[:-k + 1], rr[k:]):
		new = v1 - fst + lst
		v1 = new
		f.append(new)
else:
	f = rr
i = 0
mx = 0
index = 0
for ff in f:
	if ff > mx:
		mx = ff
		index = i
	i += 1
s = 0
for (i, t, a) in zip(range(0, len(tt)), tt, aa):
	if i >= index and i < index + k or t:
		s += a
print(s)


(n, k) = map(int, input().split())
arrs = list(map(int, input().split()))
behaves = list(map(int, input().split()))
ans = 0
max_miss = 0
miss = 0
karr = []
j = 0
for i in range(n):
	if behaves[i] == 1:
		ans += arrs[i]
	if i < k:
		if behaves[i] == 0:
			miss += arrs[i]
		max_miss = max(max_miss, miss)
		continue
	if behaves[j] == 0:
		miss -= arrs[j]
	if behaves[i] == 0:
		miss += arrs[i]
	j += 1
	max_miss = max(max_miss, miss)
print(ans + max_miss)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
suffixSum = [0] * n
suffixSum[n - 1] = a[n - 1]
sumWithoutTech = [0] * n
sumWithoutTech[n - 1] = a[n - 1] if t[n - 1] == 1 else 0
for i in range(n - 2, -1, -1):
	suffixSum[i] = suffixSum[i + 1] + a[i]
	if t[i] == 1:
		sumWithoutTech[i] = sumWithoutTech[i + 1] + a[i]
	else:
		sumWithoutTech[i] = sumWithoutTech[i + 1]
maxT = 0
curr = 0
for i in range(0, n - k + 1):
	b = curr + suffixSum[i] - (suffixSum[i + k] if i + k < n else 0) + (sumWithoutTech[i + k] if i + k < n else 0)
	maxT = max(maxT, b)
	if t[i] == 1:
		curr += a[i]
print(maxT)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
(ans, missed, awake) = (0, [], [])
for (x, i) in enumerate(t):
	if i == 1:
		ans += a[x]
		missed.append(0)
	else:
		missed.append(a[x])
	if x < k - 1:
		awake.append(0)
	elif x == k - 1:
		awake.append(sum(missed[0:x + 1]))
	else:
		awake.append(awake[x - 1] - missed[x - k] + missed[x])
print(ans + max(awake))


(n, k) = map(int, input().split())
a = [int(j) for j in input().split()]
l2 = [int(j) for j in input().split()]
g = 0
t = 0
ans = 0
for i in range(n):
	if l2[i] == 0:
		g += a[i]
	else:
		ans += a[i]
	if i >= k and l2[i - k] == 0:
		g -= a[i - k]
	t = max(t, g)
print(ans + t)


(n, k) = list(map(int, input().split()))
L = list(map(int, input().split()))
T = list(map(int, input().split()))
out = 0
for i in range(n):
	if T[i] == 1:
		out += L[i]
		L[i] = 0
ps = [0] * (n + 1)
for i in range(1, n + 1):
	ps[i] = ps[i - 1] + L[i - 1]
x = 0
for i in range(n - k + 1):
	x = max(x, ps[i + k] - ps[i])
print(x + out)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s = 0
for i in range(n):
	if i < k:
		s += A[i]
	elif B[i] == 1:
		s += A[i]
d = s
for i in range(k, n):
	if B[i - k] == 0:
		d -= A[i - k]
	if B[i] == 0:
		d += A[i]
	if d > s:
		s = d
print(s)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
s = 0
ans = 0
i = j = 0
mx = 0
while i < n:
	if b[i] == 1:
		c.append(0)
		ans += a[i]
	else:
		c.append(a[i])
	i += 1
s = sum(c[:m])
mx = s
while j < n - m:
	s += c[j + m] - c[j]
	if s > mx:
		mx = s
	j += 1
print(ans + mx)


import sys
[n, k] = map(int, sys.stdin.readline().strip().split())
ais = list(map(int, sys.stdin.readline().strip().split()))
tis = list(map(int, sys.stdin.readline().strip().split()))
slp = [(1 - ti) * ai for (ti, ai) in zip(tis, ais)]
islp = [0 for _ in range(n + 1)]
for i in range(n):
	islp[i + 1] = islp[i] + slp[i]
m = -1
for i in range(n - k + 1):
	m = max(islp[i + k] - islp[i], m)
res = sum((ti * ai for (ti, ai) in zip(tis, ais))) + m
print(res)


import sys
(n, k) = map(int, sys.stdin.readline().split())
l = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
status = 0
m = 0
for i in range(n):
	if a[i] == 1:
		m += l[i]
for i in range(k):
	if a[i] == 0:
		status += l[i]
maxx = status
for i in range(k, n):
	if a[i - k] == 0:
		status -= l[i - k]
	if a[i] == 0:
		status += l[i]
	maxx = max(status, maxx)
print(maxx + m)


def solve():
	(n, k) = list(map(int, input().split(' ')))
	tab = list(map(int, input().split(' ')))
	T = list(map(int, input().split(' ')))
	sumy = [0 for _ in range(n)]
	jedynki = 0
	for i in range(n):
		sumy[i] = sumy[i - 1]
		if T[i] == 0:
			sumy[i] += tab[i]
		else:
			jedynki += tab[i]
	maxi = sumy[k - 1]
	for i in range(1, n - k + 1):
		maxi = max(maxi, sumy[i + k - 1] - sumy[i - 1])
	print(maxi + jedynki)
solve()


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
t = [int(x) for x in input().split(' ')]
g = sum([a[x] for x in range(n) if t[x] == 1])
max_app_g = 0
app_g = 0
for i in range(n):
	if t[i] == 0:
		app_g += a[i]
	if i - k >= 0 and t[i - k] == 0:
		app_g -= a[i - k]
	if app_g > max_app_g:
		max_app_g = app_g
print(max_app_g + g)


(n, k) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s1 = 0
s2 = 0
l = [0]
for i in range(n):
	if t[i] == 1:
		s1 += a[i]
	else:
		s2 += a[i]
	l.append(s2)
s = []
for i in range(n + 1):
	if i + k < n + 1:
		s.append(l[i + k] - l[i] + s1)
print(max(s))


[n, k] = list(map(int, input().split(' ')))
lecture = list(map(int, input().split(' ')))
sleeps = list(map(int, input().split(' ')))
awakePoints = 0
summations = [0] * n
for i in range(n):
	if sleeps[i] == 1:
		awakePoints += lecture[i]
	else:
		summations[i] = lecture[i]
maxPoints = 0
pointer1 = 0
pointer2 = k
accum = 0
for i in range(k):
	accum += summations[i]
maxPoints = accum
while pointer2 < n:
	accum += summations[pointer2] - summations[pointer1]
	if accum > maxPoints:
		maxPoints = accum
	pointer1 += 1
	pointer2 += 1
print(awakePoints + maxPoints)


while True:
	try:
		(n, k) = map(int, input().split())
		(thrm, awke) = ([0] * (n + 1), [0] * (n + 1))
		thrm[1:] = map(int, input().split())
		awke[1:] = map(int, input().split())
		(i, s) = (1, 0)
		maxx = -100000.0
		slpthrm = [0] * (n + 1)
		while i <= n:
			slpthrm[i] = slpthrm[i - 1]
			if awke[i]:
				s += thrm[i]
			else:
				slpthrm[i] += thrm[i]
			i += 1
		j = k
		while j <= n:
			maxx = max(maxx, slpthrm[j] - slpthrm[j - k])
			j += 1
		print(s + maxx)
	except EOFError:
		break


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, k) = M()
a = L()
b = L()
s = 0
for i in range(n):
	if b[i] == 1:
		s += a[i]
		b[i] = 0
	else:
		b[i] = a[i]
x = [0]
for i in range(n):
	x.append(b[i] + x[-1])
p = 0
for i in range(k, n + 1):
	p = max(p, x[i] - x[i - k])
print(s + p)


R = lambda : list(map(int, input().split()))
(n, k) = R()
a = R()
t = R()
g = 0
for i in range(n):
	if t[i]:
		g += a[i]
l = 0
for i in range(0, k):
	if t[i] == 0:
		l += a[i]
max_l = l
for i in range(k, n):
	a_new = a_old = 0
	if t[i - k] == 0:
		a_old = a[i - k]
	if t[i] == 0:
		a_new = a[i]
	l += a_new - a_old
	max_l = max(max_l, l)
print(g + max_l)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc1 = [0] + a[:]
acc2 = [0] + a[:]
for i in range(1, n + 1):
	acc1[i] = acc1[i - 1]
	acc2[i] = acc2[i - 1] + a[i - 1]
	if b[i - 1]:
		acc1[i] += a[i - 1]
ans = 0
for (l, r) in zip(range(n), range(k, n + 1)):
	ans = max(ans, acc1[l] + (acc2[r] - acc2[l]) + (acc1[-1] - acc1[r]))
print(ans)


def one_case():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	t = [int(x) for x in input().split()]
	s1 = [0] * (n + 1)
	s2 = [0] * (n + 1)
	maxx = 0
	for i in range(n):
		s1[i + 1] = s1[i] + a[i]
		s2[i + 1] = s2[i] + a[i] * t[i]
		x = s1[i + 1] - s1[i - k + 1]
		y = s2[i + 1] - s2[i - k + 1]
		sk = x - y
		if maxx < sk:
			maxx = sk
	print(s2[n] - s2[0] + maxx)
t = 1
for i in range(t):
	one_case()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
last = 0
for i in range(k):
	if t[i] == 0:
		last += a[i]
ans = last
for i in range(k, n):
	if t[i - k] == 0:
		last -= a[i - k]
	if t[i] == 0:
		last += a[i]
	ans = max(last, ans)
print(ans + sum(map(lambda o: a[o] * t[o], range(n))))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
guar = sum([a[i] for i in range(n) if t[i] == 1])
prod = [(1 - t[i]) * a[i] for i in range(n)]
maximum = sum(prod[:k])
max_ind = 0
curr_sum = maximum
for i in range(n - k):
	curr_sum += prod[i + k] - prod[i]
	if curr_sum > maximum:
		maximum = curr_sum
		max_ind = i + 1
print(guar + sum(prod[max_ind:max_ind + k]))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
gain = [0] * (n - k + 1)
for i in range(k):
	if T[i] == 0:
		gain[0] += A[i]
for i in range(1, n - k + 1):
	gain[i] = gain[i - 1]
	if T[i - 1] == 0:
		gain[i] -= A[i - 1]
	if T[i + k - 1] == 0:
		gain[i] += A[i + k - 1]
sum = 0
for i in range(n):
	if T[i] == 1:
		sum += A[i]
print(sum + max(gain))


import math
import array as arr
import bisect
inarr = lambda : map(int, input().split())
(n, k) = map(int, input().split())
s = list(inarr())
b = list(inarr())
a = [0] * (n + 1)
sum1 = 0
for i in range(n):
	if b[i] == 1:
		sum1 += s[i]
ssum = 0
for i in range(n):
	if b[i] == 0:
		ssum += s[i]
	a[i + 1] = ssum
i = k
maxx = 0
while i <= n:
	if a[i] - a[i - k] > maxx:
		maxx = a[i] - a[i - k]
	i = i + 1
print(sum1 + maxx)


(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
t = list(map(int, input().strip().split()))
summ = 0
count = []
cur = 0
for i in range(n):
	if t[i] == 1:
		summ += a[i]
	else:
		cur += a[i]
	count.append(cur)
mmax = 0
for i in range(n):
	if i + k - 1 >= n:
		continue
	cur = count[i + k - 1] - count[i]
	if t[i] == 0:
		cur += a[i]
	mmax = max(cur, mmax)
print(mmax + summ)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = 0
s1 = 0
m = 0
i = 0
j = 0
while i < a:
	while j - i != b and j < a:
		if d[j]:
			s1 += c[j]
		else:
			s += c[j]
		j += 1
	m = max(m, s)
	if d[i] == 0:
		s -= c[i]
	i += 1
print(m + s1)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
p = list(map(int, input().split()))
l = [[0, None] for i in range(n)]
res = [0] * n
for i in range(n):
	if i == 0:
		l[0][1] = arr[0]
		if p[i] == 1:
			l[0][0] = arr[0]
	else:
		l[i][1] = l[i - 1][1] + arr[i]
		if p[i] == 1:
			l[i][0] = l[i - 1][0] + arr[i]
		else:
			l[i][0] = l[i - 1][0]
for i in range(n - k + 1):
	if i > 0:
		res[i] = l[i + k - 1][1] - l[i - 1][1] + l[i - 1][0] + l[-1][0] - l[i + k - 1][0]
	else:
		res[i] = l[i + k - 1][1] + l[-1][0] - l[i + k - 1][0]
print(max(res))


entrada = list(map(int, input().split()))
tamanho = entrada[0]
passo = entrada[1]
array = list(map(int, input().split()))
binario = list(map(int, input().split()))
somabinario = 0
sumAux = [0] * (tamanho + 1)
for i in range(tamanho):
	if binario[i] == 1:
		somabinario += array[i]
		array[i] = 0
for i in range(1, tamanho + 1):
	sumAux[i] = sumAux[i - 1] + array[i - 1]
contador = 0
resultado = 0
for i in range(passo, tamanho + 1):
	soma = sumAux[i] - sumAux[contador] + somabinario
	if soma > resultado:
		resultado = soma
	contador += 1
print(resultado)


def solve(n, k, a, t):
	res = 0
	for i in range(1, n + 1):
		if t[i] == 1:
			res += a[i]
			a[i] = 0
	pref = [0] * (n + 1)
	for i in range(1, n + 1):
		pref[i] = pref[i - 1] + a[i]
	temp = 0
	for i in range(n, k - 1, -1):
		temp = max(temp, pref[i] - pref[i - k])
	print(temp + res)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
a.insert(0, 0)
t.insert(0, 0)
solve(n, k, a, t)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if t[i] == 1:
		cnt += a[i]
ans = 0
for i in range(k):
	if t[i] == 0:
		ans += a[i]
su = ans
for i in range(1, n - k + 1):
	ans = ans - (not t[i - 1]) * a[i - 1] + (not t[i + k - 1]) * a[i + k - 1]
	su = max(su, ans)
print(cnt + su)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
a_comp = [0] * n
ans = 0
for i in range(n):
	if t[i]:
		ans += a[i]
	else:
		a_comp[i] = a[i]
k_sum = 0
k_sum_max = 0
for i in range(k):
	k_sum += a_comp[i]
k_sum_max = k_sum
for i in range(k, n):
	k_sum += a_comp[i]
	k_sum -= a_comp[i - k]
	if k_sum > k_sum_max:
		k_sum_max = k_sum
print(ans + k_sum_max)


from itertools import accumulate
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = sum((a[i] for i in range(n) if t[i]))
a = [0 if t[i] else a[i] for i in range(n)]
sms = list(accumulate(a))
sms.append(0)
ans += max((sms[i + k - 1] - sms[i - 1] for i in range(n - k + 1)))
print(ans)


(n, k) = map(int, input().split())
A = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
dur = 0
for i in range(n):
	if T[i]:
		dur += A[i]
		A[i] = 0
s = sum(A[:k])
b = s
for i in range(k, n):
	s = s - A[i - k] + A[i]
	b = max(s, b)
print(dur + b)


(n, k) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
the = 0
for i in range(n):
	if T[i]:
		the += A[i]
		A[i] = 0
s = sum(A[:k])
boost = s
for i in range(k, n):
	s = s - A[i - k] + A[i]
	boost = max(s, boost)
print(the + boost)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil, sqrt, gcd
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = [0]
su = 0
ans = 0
x = []
for i in range(n):
	if b[i] == 1:
		ans += a[i]
	else:
		su += a[i]
	z.append(su)
for i in range(len(z)):
	if i + k < len(z):
		x.append(ans + z[i + k] - z[i])
print(max(x))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if b[i] == 1:
		cnt += a[i]
		a[i] = 0
for i in range(1, n):
	a[i] += a[i - 1]
a.insert(0, 0)
maxx = 0
for i in range(k, len(a)):
	maxx = max(maxx, a[i] - a[i - k])
print(maxx + cnt)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
base = 0
for i in range(n):
	base += a[i] * t[i]
prefix = [(1 - t[i]) * a[i] for i in range(n)]
for i in range(1, n):
	prefix[i] += prefix[i - 1]
gain = prefix[k - 1]
for i in range(k, n):
	gain = max(gain, prefix[i] - prefix[i - k])
print(base + gain)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
bodr = [int(x) for x in input().split()]
su = 0
for i in range(n):
	if bodr[i]:
		su += a[i]
		a[i] = 0
summa = sum(a[:k])
head = 0
maxi = summa
for i in range(k, n):
	summa -= a[head]
	head += 1
	summa += a[i]
	maxi = max(summa, maxi)
print(su + maxi)


while True:
	try:

		def solution(k, a, t):
			n = len(a)
			l = r = mx = s = 0
			while r < n:
				while r < k:
					if t[r] == 0:
						s += a[r]
						mx = max(mx, s)
					r += 1
				if r == n:
					break
				if t[r] == 0:
					s += a[r]
				if t[l] == 0:
					s -= a[l]
				mx = max(mx, s)
				l += 1
				r += 1
			ts = 0
			for i in range(n):
				if t[i]:
					ts += a[i]
			print(ts + mx)

		def read():
			(n, k) = map(int, input().split())
			a = list(map(int, input().split()))
			t = list(map(int, input().split()))
			solution(k, a, t)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


(n, k) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s = sm = sm1 = 0
for i in range(n):
	if t[i]:
		sm += a[i]
for i in range(k):
	if t[i] == 0:
		sm1 += a[i]
s = sm + sm1
for i in range(k, n):
	if t[i - k] == 0:
		sm1 -= a[i - k]
	if t[i] == 0:
		sm1 += a[i]
	s = max(s, sm + sm1)
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
tmp = []
i = j = s = 0
while j < n:
	if j < k:
		if t[j] == 0:
			s += a[j]
		j += 1
	else:
		tmp.append(s)
		if t[i] == 0:
			s -= a[i]
		i += 1
		if t[j] == 0:
			s += a[j]
		j += 1
tmp.append(s)
ans = 0
for i in range(n):
	if t[i] == 1:
		ans += a[i]
ans += max(tmp)
print(ans)


(n, k) = map(int, input().split())
inp = [int(x) for x in input().split()]
behaviour_check = [int(x) for x in input().split()]
window_sum = 0
window_active = 0
total_sum = 0
for i in range(n):
	total_sum += inp[i] * behaviour_check[i]
for i in range(k):
	window_sum += inp[i] * behaviour_check[i]
	window_active += inp[i]
maxi = total_sum + window_active - window_sum
for j in range(k, n):
	window_active += inp[j] - inp[j - k]
	window_sum += inp[j] * behaviour_check[j] - inp[j - k] * behaviour_check[j - k]
	if maxi < total_sum + window_active - window_sum:
		maxi = total_sum + window_active - window_sum
print(maxi)


(n, k) = map(int, input().split())
theo = tuple(map(int, input().split()))
awak = tuple(map(int, input().split()))
tot = sum((theo[i] for i in range(n) if awak[i]))
cur = sum((theo[i] for i in range(k) if not awak[i]))
best = cur
for i in range(n - k):
	if not awak[i]:
		cur -= theo[i]
	if not awak[i + k]:
		cur += theo[i + k]
	if cur > best:
		best = cur
print(tot + best)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
from bisect import bisect_right
import bisect
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ls = list(map(int, input().split()))
c = 0
for i in range(n):
	if ls[i] == 1:
		c += arr[i]
		arr[i] = 0
for i in range(1, n):
	arr[i] += arr[i - 1]
ma = 0
for i in range(n):
	s = arr[min(n - 1, i + k - 1)]
	if i > 0:
		s -= arr[i - 1]
	if s > ma:
		ma = s
print(c + ma)


import sys
import collections
first_line = sys.stdin.readline().split()
n = int(first_line[0])
k = int(first_line[1])
theorems = sys.stdin.readline().split()
behavior = sys.stdin.readline().split()
summa = 0
for i in range(n):
	theorems[i] = int(theorems[i])
	behavior[i] = int(behavior[i])
	if behavior[i] == 1:
		summa += theorems[i]
		theorems[i] = 0
maximum = sum(theorems[0:0 + k])
b = maximum
for i in range(1, n - k + 1):
	a = b - theorems[i - 1] + theorems[i + k - 1]
	if a > maximum:
		maximum = a
	b = a
sys.stdout.write(str(maximum + summa))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
maxx = 0
summ = 0
for i in range(k):
	if b[i] == 0:
		s += a[i]
	else:
		summ += a[i]
maxx = s
for i in range(k, n):
	if b[i] == 0:
		s += a[i]
	else:
		summ += a[i]
	if b[i - k] == 0:
		s -= a[i - k]
	if s > maxx:
		maxx = s
print(maxx + summ)


from sys import stdin, stdout
from itertools import accumulate
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	b = lst()
	ps = list(accumulate(a))
	dp = [[0 for _ in range(2)] for _ in range(1 + n)]
	for i in range(1, n + 1):
		dp[i][0] = dp[i - 1][0] + a[i - 1] * b[i - 1]
		dp[i][1] = max(dp[i - 1][1] + a[i - 1] * b[i - 1], ps[i - 1] - (ps[i - k - 1] if i - k - 1 >= 0 else 0) + dp[max(i - k, 0)][0])
	print(max(dp[n]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
prefix = []
if n == 1:
	print(a[0])
elif n == 2:
	if k == 2:
		print(a[0] + a[1])
	elif t[0] == 0 and t[1] == 0:
		print(max(a))
	elif t[0] + t[1] == 1:
		print(sum(a))
	else:
		print(sum(a))
else:
	if t[0] == 1:
		prefix.append(a[0])
	else:
		prefix.append(0)
	for i in range(1, n):
		if t[i] == 1:
			prefix.append(prefix[-1] + a[i])
		else:
			prefix.append(prefix[-1])
	kolvo = []
	sum1 = 0
	for i in range(k):
		sum1 += a[i]
	kolvo.append(sum1)
	for i in range(k, n):
		sum1 -= a[i - k]
		sum1 += a[i]
		kolvo.append(sum1)
	ans = -10000000000000000000000000
	for i in range(n - k + 1):
		if i == 0:
			if kolvo[0] + prefix[-1] - prefix[i + 2] > ans:
				ans = kolvo[0] + prefix[-1] - prefix[i + k - 1]
		elif kolvo[i] + prefix[i - 1] + prefix[-1] - prefix[i + k - 1] > ans:
			ans = kolvo[i] + prefix[i - 1] + prefix[-1] - prefix[i + k - 1]
	print(ans)


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(n, k) = getInputIntList()
arr = getInputIntList()
arr1 = getInputIntList()
sleep_arr = [0] * n
s = 0
for i in range(n):
	if arr1[i] == 1:
		s += arr[i]
	else:
		sleep_arr[i] = arr[i]
pre_sum = [0]
for i in sleep_arr:
	pre_sum.append(pre_sum[len(pre_sum) - 1] + i)
m = -1
for i in range(n - k + 1):
	ps = pre_sum[i + k] - pre_sum[i]
	if ps + s > m:
		m = ps + s
if m == -1:
	print(s + pre_sum[len(pre_sum) - 1])
else:
	print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
count = 0
aux = 0
for i in range(n):
	if t[i] == 1:
		count += a[i]
		a[i] = 0
	elif i < k and t[i] == 0:
		aux += a[i]
aux_count = aux
for i in range(k, n):
	aux_count += a[i] - a[i - k]
	if aux_count > aux:
		aux = aux_count
res = count + aux
print(res)


(n, k) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
t = [int(i) for i in input().split(' ')]
pre = [0] * (n + 1)
x = 0
for i in range(n):
	if t[i] == 1:
		x += a[i]
		a[i] = 0
	pre[i] = pre[i - 1] + a[i]
m = 0
for i in range(n - k + 1):
	m = max(m, pre[i + k - 1] - pre[i - 1])
print(m + x)


(n, k) = map(int, input().split())
y = list(map(int, input().split()))
z = list(map(int, input().split()))
s = []
s.append(y[0])
t = []
t.append(y[0] * z[0])
l = [0] * n
l[n - 1] = y[n - 1] * z[n - 1]
for i in range(1, n):
	s.append(s[i - 1] + y[i])
	t.append(t[i - 1] + y[i] * z[i])
	l[n - 1 - i] = l[n - i] + y[n - 1 - i] * z[n - 1 - i]
ans = t[n - 1]
s.insert(0, 0)
t.insert(0, 0)
l.append(0)
for i in range(0, n - k + 1):
	temp = s[i + k] - s[i] + t[i] + l[i + k]
	if temp > ans:
		ans = temp
print(ans)


inp = lambda : map(int, input().split())
(n, k) = inp()
a = [*inp()]
b = [*inp()]
c = []
ans = 0
for i in range(n):
	c.append(a[i] if b[i] == 0 else 0)
	ans += a[i] if b[i] == 1 else 0
more = s = sum(c[:k])
for i in range(1, n - k + 1):
	s = s - c[i - 1] + c[i + k - 1]
	more = max(more, s)
print(ans + more)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
b = 0
c = 0
for i in range(k):
	b += a[i]
	if t[i] == 1:
		c += a[i]
idx = 0
cnt = b - c
i = k
while i < n:
	b += a[i]
	b -= a[i - k]
	if t[i] == 1:
		c += a[i]
	if t[i - k] == 1:
		c -= a[i - k]
	if b - c > cnt:
		idx = i - k + 1
		cnt = b - c
	i += 1
print(sum([a[i] for i in range(n) if t[i] == 1]) + cnt)


(n, k) = map(int, input().strip().split(' '))
L = list(map(int, input().split(' ')))
M = list(map(int, input().split(' ')))
sum1 = [0] * (n + 1)
sum2 = [0] * (n + 1)
for i in range(1, n + 1):
	sum1[i] = sum1[i - 1] + L[i - 1] * M[i - 1]
	sum2[i] = sum2[i - 1] + L[i - 1]
ans = 0
for i in range(1, n - k + 2):
	res = sum2[i + k - 1] - sum2[i - 1]
	res = sum1[i - 1] + res
	res += sum1[n] - sum1[i + k - 1]
	ans = max(res, ans)
print(ans)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, k) = int_array()
a = int_array()
t = int_array()
arr = []
onizuka = 0
for i in range(n):
	if t[i] == 1:
		arr.append(0)
		onizuka += a[i]
	else:
		arr.append(a[i])
for i in range(1, n):
	arr[i] += arr[i - 1]
ans = arr[k - 1]
for i in range(k, n):
	ans = max(ans, arr[i] - arr[i - k])
ans += onizuka
print(ans)


(N, k) = map(int, input().split())
A = list(map(int, input().split()))
t = list(map(int, input().split()))
prefix_sums = [A[0] if t[0] else 0]
for i in range(1, N):
	prefix_sums.append(prefix_sums[-1] + (A[i] if t[i] else 0))
curr_sum = ans = prefix_sums[-1]
for i in range(k):
	if not t[i]:
		curr_sum += A[i]
ans = max(ans, curr_sum)
for i in range(k, N):
	if not t[i]:
		curr_sum += A[i]
	if not t[i - k]:
		curr_sum -= A[i - k]
	ans = max(ans, curr_sum)
print(ans)


(n, k) = map(int, input().split())
marks = [int(i) for i in input().split()]
awake = [int(i) for i in input().split()]
ans = sum((marks[i] for i in range(n) if awake[i] == 1))
for i in range(n):
	if awake[i] == 1:
		marks[i] = 0
maxi = sum(marks[0:k])
sm = sum(marks[0:k])
for i in range(k, n):
	sm = sm + marks[i] - marks[i - k]
	maxi = max(maxi, sm)
print(maxi + ans)


(N, K) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
T = list(map(int, input().split(' ')))
Ac1 = [0] * (N + 1)
Ac2 = [0] * (N + 1)
resp = 0
for i in range(1, N + 1):
	Ac1[i] = Ac1[i - 1] + A[i - 1]
	Ac2[i] = Ac2[i - 1]
	if T[i - 1] == 1:
		Ac2[i] += A[i - 1]
for L in range(len(Ac2) - K):
	R = L + K
	sum1 = Ac1[R] - Ac1[L]
	sum2 = Ac2[R] - Ac2[L]
	resp = max(resp, sum1 - sum2)
print(Ac2[-1] + resp)


from sys import stdout, stdin

def acc_sum(_list, awake):
	acc = []
	_sum = 0
	for i in range(len(_list)):
		if awake[i] == 1:
			_sum += _list[i]
		acc += [_sum]
	return acc

def calulate_sum(i, j, _list):
	if i > 0:
		return _list[j] - _list[i - 1]
	return _list[j]

def lecture(theorems, awake, n, k):
	theorems_1_acc = acc_sum(theorems, [1 for x in range(len(theorems))])
	theorems_real_acc = acc_sum(theorems, awake)
	result = 0
	for i in range(len(theorems) - k + 1):
		j = i + k - 1
		using_k = calulate_sum(i, j, theorems_1_acc)
		not_using_k = calulate_sum(i, j, theorems_real_acc)
		result = max(result, using_k - not_using_k)
	return result + theorems_real_acc[-1]

def get_numbers(_list):
	return (int(_list[0]), int(_list[1]))
(n, k) = get_numbers(stdin.readline().replace('\n', '').split(' '))
a = [int(x) for x in stdin.readline().replace('\n', '').split(' ')]
t = [int(x) for x in stdin.readline().replace('\n', '').split(' ')]
print(lecture(a, t, n, k))


import random
(n, k) = map(int, input().split())
H = list(map(int, input().split()))
G = list(map(int, input().split()))
ans = 0
for b in range(n):
	ans += H[b] * G[b]
Sums = [0] * n
Sums[0] = H[0] * abs(G[0] - 1)
for j in range(1, n):
	Sums[j] = Sums[j - 1] + H[j] * abs(G[j] - 1)
max_c = Sums[k - 1]
for m in range(k, n):
	temp = Sums[m] - Sums[m - k]
	if temp > max_c:
		max_c = temp
print(max_c + ans)


def funcao(teoremas, comp, k):
	maior = 0
	soma = 0
	i = 0
	while i < k:
		if comp[i] == '0':
			soma += teoremas[i]
		i += 1
	maior = soma
	i = k
	while i < len(teoremas):
		if comp[i - k] == '0':
			soma -= teoremas[i - k]
		if comp[i] == '0':
			soma += teoremas[i]
		maior = max(maior, soma)
		i += 1
	return maior
k = int(input().split()[1])
teoremas = list(map(int, input().split()))
comp = input().split()
soma = 0
i = 0
while i < len(teoremas):
	if comp[i] == '1':
		soma += teoremas[i]
	i += 1
print(funcao(teoremas, comp, k) + soma)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
sum = 0
for i in range(n):
	if p[i] == 1:
		sum += t[i]
		t[i] = 0
Max = 0
for i in range(k):
	Max += t[i]
kol = Max
for i in range(1, n - k + 1):
	kol = kol + t[i + k - 1] - t[i - 1]
	if kol > Max:
		Max = kol
print(sum + Max)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
num1 = 0
for i in range(n):
	if b[i] == 0:
		c[i] = a[i]
	else:
		num1 += a[i]
num2 = 0
s = sum(c[:k])
for i in range(n - k + 1):
	num2 = max(num2, num1 + s)
	if i != n - k:
		s = s - c[i] + c[i + k]
print(num2)


import sys
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
(n, k) = map(int, input().split())
t = L()
b = L()
extra = 0
for i in range(n):
	if b[i] == 1:
		extra += t[i]
s = extra
for i in range(k):
	if b[i] == 0:
		s += t[i]
big = s
for i in range(1, n - k + 1):
	if b[i - 1] == 0:
		s -= t[i - 1]
	if b[i + k - 1] == 0:
		s += t[i + k - 1]
	big = max(big, s)
print(big)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = [0]
ans = 0
e = 0
for i in range(n):
	if i > 0:
		p.append(p[i - 1])
	if b[i] == 1:
		ans += a[i]
	else:
		p[i] += a[i]
for i in range(k - 1, n):
	e = max(e, p[i] - (p[i - k] if i - k >= 0 else 0))
print(ans + e)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
d = [0] * n
for i in range(k):
	if t[i] == 0:
		d[0] += a[i]
for i in range(1, n - k + 1):
	d[i] = d[i - 1]
	if t[i - 1] == 0:
		d[i] -= a[i - 1]
	if t[i + k - 1] == 0:
		d[i] += a[i + k - 1]
p = 0
for i in range(n):
	if t[i] == 1:
		p += a[i]
print(max(d) + p)


sig = 0
asl = []
wkd = []
inp = input().split()
n = int(inp[0])
k = int(inp[1])
inp = input().split()
a = []
[a.append(int(i)) for i in inp]
inp = input().split()
for (x, i) in enumerate(inp):
	if i == '1':
		sig += a[x]
		asl.append(0)
	else:
		asl.append(a[x])
	if x < k - 1:
		wkd.append(0)
	elif x == k - 1:
		wkd.append(sum(asl[0:x + 1]))
	else:
		wkd.append(wkd[x - 1] - asl[x - k] + asl[x])
sig += max(wkd)
print(sig)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		t = LI()
		r = 0
		for i in range(n):
			if t[i]:
				r += a[i]
				a[i] = 0
		m = u = sum(a[:k])
		for i in range(k, n):
			u += a[i]
			u -= a[i - k]
			if m < u:
				m = u
		rr.append(r + m)
	return JA(rr, '\n')
print(main())


def solve(n, k, theorem_num, asleep):
	expected_theorem = [0] * (n + 1)
	maximum_theorem = [0] * (n + 1)
	expected_theorem[1] = theorem_num[0] * asleep[0]
	maximum_theorem[1] = theorem_num[0]
	for i in range(2, n + 1):
		expected_theorem[i] = expected_theorem[i - 1] + theorem_num[i - 1] * asleep[i - 1]
		maximum_theorem[i] = maximum_theorem[i - 1] + theorem_num[i - 1]
	ans = -1
	for i in range(1, n - k + 2):
		tmp = maximum_theorem[i + k - 1] - maximum_theorem[i - 1] - expected_theorem[i + k - 1] + expected_theorem[i - 1]
		ans = max(ans, tmp)
	return ans + expected_theorem[n]

def main():
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	theorem_num = input().split()
	asleep = input().split()
	for i in range(n):
		theorem_num[i] = int(theorem_num[i])
		asleep[i] = int(asleep[i])
	print(solve(n, k, theorem_num, asleep))
main()


import sys
input = sys.stdin.readline
import math
import copy
import collections
from collections import deque
import heapq
import itertools
from collections import defaultdict
from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
pre = [0]
for i in range(n):
	if t[i] == 0:
		pre.append(pre[i] + a[i])
	else:
		pre.append(pre[i])
mx = 0
for i in range(n - k + 1):
	l = i
	r = i + k
	ans = pre[r] - pre[l]
	mx = max(mx, ans)
ans = 0
for i in range(n):
	if t[i] == 1:
		ans += a[i]
print(ans + mx)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
left = 0
right = 0
count_c = 0
count_max = 0
for left in range(n):
	if left > 0 and t[left - 1] == 0:
		count_c -= a[left - 1]
	if t[left] == 0:
		while right < n and right - left < k:
			if t[right] == 0:
				count_c += a[right]
			right += 1
	count_max = max(count_c, count_max)
	left += 1
count = 0
for i in range(n):
	if t[i] == 1:
		count += a[i]
print(count + count_max)


(n, k) = map(int, input().split())
d1 = list(map(int, input().split()))
d2 = list(map(int, input().split()))
total = 0
for i in range(n):
	total += d1[i] * d2[i]
cur = 0
for i in range(k):
	cur += d1[i] * (1 - d2[i])
m = cur
for i in range(n - k):
	temp = cur - d1[i] * (1 - d2[i]) + d1[k + i] * (1 - d2[k + i])
	cur = temp
	if cur > m:
		m = cur
print(total + m)


inp = lambda : map(int, input().rstrip().split())
(n, k) = inp()
a = list(inp())
t = list(inp())
written = [0]
total = [0]
for i in range(n):
	if t[i] == 1:
		written.append(written[-1] + a[i])
	else:
		written.append(written[-1])
	total.append(total[-1] + a[i])
maxm = 0
for i in range(1, n - k + 2):
	m = total[i + k - 1] - total[i - 1] + written[i - 1] + written[n] - written[i + k - 1]
	maxm = max(maxm, m)
print(maxm)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
mx = 0
for x in range(0, k):
	if l2[x] == 0:
		mx += l1[x]
s = mx
for i in range(1, n - k + 1):
	if l2[i + k - 1] == 0:
		s += l1[i + k - 1]
	if l2[i - 1] == 0:
		s -= l1[i - 1]
	mx = max(mx, s)
for y in range(n):
	if l2[y] == 1:
		mx += l1[y]
print(mx)