from itertools import accumulate
import sys
def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *A, = map(int, input().split())
    ans = solve1(A, K)
    ans = max(ans, solve2(A, K))
    A.reverse()
    ans = max(ans, solve2(A, K))
    print(ans)

def solve1(A, K):
    N = len(A)
    C = [0] + list(accumulate(A))
    D = [0] * (N + 1)
    for i, a in enumerate(A):
        D[i + 1] = D[i] + (a if a > 0 else 0)
    res = -10 ** 10
    for i in range(1, N - K + 1):
        s = D[i] + D[N] - D[i + K]
        t = C[i + K] - C[i - 1]
        s += t if t > 0 else 0
        res = max(res, s)
    return res

def solve2(A, K):
    s = sum(A[:K])
    if s < 0: s = 0
    for i in range(K, len(A)):
        if A[i] > 0: s += A[i]
    return s

if __name__ == '__main__':
    main()
