import sys

import numpy as np

from numba import njit



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N, K = list(map(int, readline().split()))

A = np.array(read().split(), np.int64)



@njit('(i8,i8,i8[:])', cache=True)

def main(N, K, A):

    B = np.maximum(A, 0)

    Acum = np.zeros(len(A) + 1, np.int64)

    Bcum = np.zeros(len(A) + 1, np.int64)

    Acum[1:] = np.cumsum(A)

    Bcum[1:] = np.cumsum(B)

    ret = -(10**18)

    for l in range(N - K + 1):

        r = l + K

        sum1 = Bcum[l]

        sum2 = Bcum[-1] - Bcum[r]

        sum3 = Acum[r] - Acum[l]

        x = sum1 + sum2 + max(sum3, 0)

        ret = max(ret, x)

    return ret



print((main(N, K, A)))
import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N, K = list(map(int, readline().split()))

A = np.array(read().split(), np.int64)



def main(N, K, A):

    B = np.maximum(A, 0)

    Acum = np.zeros(N + 1, np.int64)

    Bcum = np.zeros(N + 1, np.int64)

    Acum[1:] = np.cumsum(A)

    Bcum[1:] = np.cumsum(B)

    sum1 = Bcum[:N - K + 1]

    sum2 = Bcum[-1] - Bcum[K:]

    sum3 = Acum[K:] - Acum[:N - K + 1]

    x = sum1 + sum2 + np.maximum(sum3, 0)

    return x.max()



print((main(N, K, A)))
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(read().split(), np.int64)


@njit("(i8,i8,i8[:])", cache=True)
def main(N, K, A):
    B = np.maximum(A, 0)
    Acum = np.zeros(len(A) + 1, np.int64)
    Bcum = np.zeros(len(A) + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum[1:] = np.cumsum(B)
    ret = -(10**18)
    for l in range(N - K + 1):
        r = l + K
        sum1 = Bcum[l]
        sum2 = Bcum[-1] - Bcum[r]
        sum3 = Acum[r] - Acum[l]
        x = sum1 + sum2 + max(sum3, 0)
        ret = max(ret, x)
    return ret


print((main(N, K, A)))

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = np.array(read().split(), np.int64)


def main(N, K, A):
    B = np.maximum(A, 0)
    Acum = np.zeros(N + 1, np.int64)
    Bcum = np.zeros(N + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum[1:] = np.cumsum(B)
    sum1 = Bcum[: N - K + 1]
    sum2 = Bcum[-1] - Bcum[K:]
    sum3 = Acum[K:] - Acum[: N - K + 1]
    x = sum1 + sum2 + np.maximum(sum3, 0)
    return x.max()


print((main(N, K, A)))

-from numba import njit -@njit("(i8,i8,i8[:])", cache=True) -    Acum = np.zeros(len(A) + 1, np.int64) -    Bcum = np.zeros(len(A) + 1, np.int64) +    Acum = np.zeros(N + 1, np.int64) +    Bcum = np.zeros(N + 1, np.int64) -    ret = -(10**18) -    for l in range(N - K + 1): -        r = l + K -        sum1 = Bcum[l] -        sum2 = Bcum[-1] - Bcum[r] -        sum3 = Acum[r] - Acum[l] -        x = sum1 + sum2 + max(sum3, 0) -        ret = max(ret, x) -    return ret +    sum1 = Bcum[: N - K + 1] +    sum2 = Bcum[-1] - Bcum[K:] +    sum3 = Acum[K:] - Acum[: N - K + 1] +    x = sum1 + sum2 + np.maximum(sum3, 0) +    return x.max()