n,k=map(int,input().split())
arr=list(map(int,input().split()))
brr=list(map(lambda x: max(x,0),arr))
crr=[0]
cum=0
for b in brr[:(n-k)]:
    cum+=b
    crr.append(cum)
drr=[0]
cum=0
for b in list(reversed(brr))[:(n-k)]:
    cum+=b
    drr.append(cum)
drr.reverse()
K=sum(arr[:k])
krr=[]
for i in range(n-k):
    krr.append(max(0,K))
    K-=arr[i]
    K+=arr[i+k]
krr.append(max(0,K))

ans=0
for i in range(n-k+1):
    ans=max(ans,crr[i]+drr[i]+krr[i])
print(ans)
