N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))


if N == K:
	print(max(0, sum(a)))
else:
	imosW = [0]*(N+2)
	imosB = [0]*(N+2)
	for i in range(1, N+1):
		imosW[i] = max(0, a[i]) + imosW[i-1]
		imosB[i] = min(0, a[i]) + imosB[i-1]

	sepW = -1
	mini = int(1e18)
	for i in range(K, N + 1):
		if mini > imosW[i] - imosW[i-K]:
			mini = imosW[i] - imosW[i-K]
			sepW = (i-K, i)

	ansW = 0
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepW[0] and i <= sepW[1]):
			ansW += a[i]

	##
	sepB = -1
	maxm = int(-1e18)
	for i in range(K, N+1):
		if maxm < imosB[i] - imosB[i-K]:
			maxm = imosB[i] - imosB[i-K]
			sepB = (i-K, i)
	ansB = imosB[sepB[1]] - imosB[sepB[0]]
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepB[0] and i <= sepB[1]):
			ansB += a[i]

	print(max(max(ansW, ansB), sum(a)))
