N,K = map(int,input().split())
*A, = map(int,input().split())

L = [0]*(N+2)
R = [0]*(N+2)
for i in range(1,N+1):
    L[i] = L[i-1]+max(0,A[i-1])
for i in range(N,0,-1):
    R[i] = R[i+1]+max(0,A[i-1])

ans = 0
S = sum(A[:K])
for i in range(N-K+1):
    ans = max(ans,L[i]+max(0,S)+R[i+K+1])
    S += -A[i] + A[(K+i)%N]
print(ans)