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

def k(A):
  dp = [ [-10**10] *2 for _ in range(N+1)]
  dp[0][0] = 0
  for i in range(0, N-K+1):
    #print("now: ", i, "A[",i+K-1,"]", "sum(", i,":",i+K,"]")
    #print("\tdp[{}]:".format(i), dp[i])
    dp[i+1][1] = max(
        dp[i+1][1],
        dp[i][1] + A[i+K-1],
        dp[i][0] + sum(A[i:i+K]))
    dp[i+1][0] =max(
      dp[i+1][0],
      dp[i][0],
      dp[i][1] - sum(A[i:i+K-1])
      )
  #print(dp)
  return max(dp[N-K+1])

ans = max(k(A), k(list(reversed(A))))
print(ans)
