import sys

stdin = sys.stdin



def li(): return [int(x) for x in stdin.readline().split()]

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return [float(x) for x in stdin.readline().split()]

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(ns())

def nf(): return float(ns())



from itertools import accumulate



n,k = li()

a = li()



a_cum = list(accumulate([0] + a))

a_pl = [ai if ai>0 else 0 for ai in a]

a_left = list(accumulate([0] + a_pl))

a_right = list(accumulate([0] + a_pl[::-1]))



ans = 0



for i in range(n-k+1):

    # a[i:i+k]を黒にするとき

    cand = a_cum[i+k] - a_cum[i]

    cand += (a_left[i] + a_right[n-(i+k)])

    ans = max(ans,cand)

    

    

    # a[i:i+k]を白にするとき

    cand = 0

    cand += (a_left[i] + a_right[n-(i+k)])

    ans = max(ans,cand)

    

    

print(ans)
import sys

stdin = sys.stdin

 

sys.setrecursionlimit(10**5) 

 

def li(): return map(int, stdin.readline().split())

def li_(): return map(lambda x: int(x)-1, stdin.readline().split())

def lf(): return map(float, stdin.readline().split())

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



n,k = li()

a = list(li())



acc_all = [0]

acc_pos = [0]



for ai in a:

    if ai > 0:

        acc_all.append(acc_all[-1] + ai)

        acc_pos.append(acc_pos[-1] + ai)

    else:

        acc_all.append(acc_all[-1] + ai)

        acc_pos.append(acc_pos[-1])



ans = 0    

for st in range(n-k+1):

    black = (acc_all[st+k] - acc_all[st])\

            + (acc_pos[n] - acc_pos[st+k])\

            + (acc_pos[st] - acc_pos[0])

    white = (acc_pos[n] - acc_pos[st+k])\

            + (acc_pos[st] - acc_pos[0])



    ans = max(ans, black, white)

    

print(ans)

    

import sys

stdin = sys.stdin


def li():
    return [int(x) for x in stdin.readline().split()]


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return [float(x) for x in stdin.readline().split()]


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(ns())


def nf():
    return float(ns())


from itertools import accumulate

n, k = li()
a = li()
a_cum = list(accumulate([0] + a))
a_pl = [ai if ai > 0 else 0 for ai in a]
a_left = list(accumulate([0] + a_pl))
a_right = list(accumulate([0] + a_pl[::-1]))
ans = 0
for i in range(n - k + 1):
    # a[i:i+k]を黒にするとき
    cand = a_cum[i + k] - a_cum[i]
    cand += a_left[i] + a_right[n - (i + k)]
    ans = max(ans, cand)
    # a[i:i+k]を白にするとき
    cand = 0
    cand += a_left[i] + a_right[n - (i + k)]
    ans = max(ans, cand)
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return map(int, stdin.readline().split())


def li_():
    return map(lambda x: int(x) - 1, stdin.readline().split())


def lf():
    return map(float, stdin.readline().split())


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


n, k = li()
a = list(li())
acc_all = [0]
acc_pos = [0]
for ai in a:
    if ai > 0:
        acc_all.append(acc_all[-1] + ai)
        acc_pos.append(acc_pos[-1] + ai)
    else:
        acc_all.append(acc_all[-1] + ai)
        acc_pos.append(acc_pos[-1])
ans = 0
for st in range(n - k + 1):
    black = (
        (acc_all[st + k] - acc_all[st])
        + (acc_pos[n] - acc_pos[st + k])
        + (acc_pos[st] - acc_pos[0])
    )
    white = (acc_pos[n] - acc_pos[st + k]) + (acc_pos[st] - acc_pos[0])
    ans = max(ans, black, white)
print(ans)

+sys.setrecursionlimit(10**5) -    return [int(x) for x in stdin.readline().split()] +    return map(int, stdin.readline().split()) -    return [int(x) - 1 for x in stdin.readline().split()] +    return map(lambda x: int(x) - 1, stdin.readline().split()) -    return [float(x) for x in stdin.readline().split()] +    return map(float, stdin.readline().split()) -    return int(ns()) +    return int(stdin.readline()) -    return float(ns()) +    return float(stdin.readline()) -from itertools import accumulate - -a = li() -a_cum = list(accumulate([0] + a)) -a_pl = [ai if ai > 0 else 0 for ai in a] -a_left = list(accumulate([0] + a_pl)) -a_right = list(accumulate([0] + a_pl[::-1])) +a = list(li()) +acc_all = [0] +acc_pos = [0] +for ai in a: +    if ai > 0: +        acc_all.append(acc_all[-1] + ai) +        acc_pos.append(acc_pos[-1] + ai) +    else: +        acc_all.append(acc_all[-1] + ai) +        acc_pos.append(acc_pos[-1]) -for i in range(n - k + 1): -    # a[i:i+k]を黒にするとき -    cand = a_cum[i + k] - a_cum[i] -    cand += a_left[i] + a_right[n - (i + k)] -    ans = max(ans, cand) -    # a[i:i+k]を白にするとき -    cand = 0 -    cand += a_left[i] + a_right[n - (i + k)] -    ans = max(ans, cand) +for st in range(n - k + 1): +    black = ( +        (acc_all[st + k] - acc_all[st]) +        + (acc_pos[n] - acc_pos[st + k]) +        + (acc_pos[st] - acc_pos[0]) +    ) +    white = (acc_pos[n] - acc_pos[st + k]) + (acc_pos[st] - acc_pos[0]) +    ans = max(ans, black, white)