import sys
input = sys.stdin.readline
N,K = map(int,input().split())
A = list(map(int,input().split()))
class BIT:
    def __init__(self,data,op,default):
        self.op = op
        self.default = default
        N = len(data)
        self.l = 2**((N-1).bit_length())
        self.data = [default]*(self.l+1)
        for i in range(1,N+1):
            v = data[i-1]
            while i <= self.l:
                self.data[i] = self.op(self.data[i], v)
                i += i & -i
    def add(self,i,v):
        i += 1
        while i <= self.l:
            self.data[i] = self.op(self.data[i], v)
            i += i & -i

    def get(self,i):
        if i == -1:
            return 0
        res = 0
        i += 1
        while i > 0:
            res = self.op(res, self.data[i])
            i -= i & -i
        return res

B = [a if a >= 0 else 0 for a in A]

bit = BIT(B, lambda x,y : x+y, 0)

cs = [0]
t = 0
for a in A:
    t += a
    cs.append(t)

ans = -10**15
for i in range(N-K+1):
    r = bit.get(N-1) - bit.get(K+i-1) + bit.get(i-1)
    b = cs[i+K] - cs[i]
    ans = max(ans,r,r+b)
print(ans)


