# B - Contiguous Repainting
N,K = map(int,input().split())
a = [0] + list(map(int,input().split()))
ans = 0
tmp = [0,0]
for i in range(1,K+1):
    ans += max(0,a[i])
    tmp[a[i]>=0] += abs(a[i])
loss = min(tmp)
for i in range(K+1,N+1):
    ans += max(0,a[i])
    tmp[a[i-K]>=0] -= abs(a[i-K])
    tmp[a[i]>=0] += abs(a[i])
    loss = min(loss,min(tmp))
print(ans-loss)