#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    b = LI()
    ans = []
    for j in range(n):
        for i in range(len(b))[::-1]:
            if b[i] == i+1:
                x = b.pop(i)
                ans.append(x)
                break
    if b:
        print(-1)
    else:
        print(*ans[::-1],sep = "\n")
    return

#B
def B():
    n,a,b,c,d = LI()
    s = S()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    k = b
    while b < d:
        if s[b+1] == ".":
            b += 1
        else:
            if s[b+2] == "#":
                print("No")
                return
            b += 2
    b = k
    if c < d:
        while a < c:
            if s[a+1] == ".":
                a += 1
            else:
                if s[a+2] == "#":
                    print("No")
                    return
                a += 2
        print("Yes")
    else:
        for i in range(b-1,d):
            if s[i:i+3].count(".") == 3:
                print("Yes")
                return
        print("No")
    return

#C
def C():
    n,a,b,c,d = LI()
    if abs(b-a) > (n-1)*d:
        print("NO")
        return
    if 2*c <= (n-1)*(d-c):
        print("YES")
        return
    mi = a-(n-1)*d
    m = c+d
    f = 1+(n-1)*(d-c)
    if f >= m:
        print("YES")
        return
    if (b-mi)%m < f:
        print("YES")
    else:
        print("NO")
    return

#D
def D():
    s = S()
    n = len(s)
    ans = 0
    for i in range(n):
        if s[i] == "U":
            ans += n-i-1
            ans += 2*i
        else:
            ans += 2*(n-i-1)
            ans += i
    print(ans)
    return

#E
def E():
    n = I()
    a = LI()
    a.sort()
    b = [a[i] for i in range(n)]
    for i in range(n-1):
        b[i+1] += b[i]
    for i in range(n-1)[::-1]:
        if a[i+1] > 2*b[i]:
            break
    else:
        print(n)
        return
    print(n-i-1)
    return

#F
def F():
    n,k = LI()
    a = LI()
    b = [a[i] for i in range(n)]
    b.append(0)
    for i in range(n)[::-1]:
        b[i] += b[i+1]
    l = [0]*(n+1)
    for i in range(n):
        if a[i] > 0:
            l[i+1] += a[i]
        l[i+1] += l[i]

    r = [0]*(n+1)
    for i in range(n)[::-1]:
        if a[i] > 0:
            r[i] += a[i]
        r[i] += r[i+1]
    ans = -float("inf")
    for i in range(n-k+1):
        j = i+k
        ans = max(ans, l[i]+r[j]+max(0,b[i]-b[j]))
    print(ans)
    return

#Solve
if __name__ == "__main__":
    F()
