from itertools import accumulate

n,k,*a=list(map(int,open(0).read().split()))

p=[x if x>0 else 0 for x in a]

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

p_acc=[0]+list(accumulate(p))

rev_p_acc=[0]+list(accumulate(p[::-1]))

print((max(max(0,acc[k+i]-acc[i])+p_acc[i]+rev_p_acc[n-k-i] for i in range(n-k+1))))
from itertools import accumulate

def main():

	n, k, *a = list(map(int, open(0).read().split()))

	p = [x if x > 0 else 0 for x in a]

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

	p_acc = [0] + list(accumulate(p))

	rev_p_acc = [0] + list(accumulate(p[::-1]))

	print((max(max(0, acc[k + i] - acc[i]) + p_acc[i] + rev_p_acc[n - k - i] for i in range(n - k + 1))))

	

if __name__=="__main__":

	main()
from itertools import accumulate

n, k, *a = list(map(int, open(0).read().split()))
p = [x if x > 0 else 0 for x in a]
acc = [0] + list(accumulate(a))
p_acc = [0] + list(accumulate(p))
rev_p_acc = [0] + list(accumulate(p[::-1]))
print(
    (
        max(
            max(0, acc[k + i] - acc[i]) + p_acc[i] + rev_p_acc[n - k - i]
            for i in range(n - k + 1)
        )
    )
)

from itertools import accumulate


def main():
    n, k, *a = list(map(int, open(0).read().split()))
    p = [x if x > 0 else 0 for x in a]
    acc = [0] + list(accumulate(a))
    p_acc = [0] + list(accumulate(p))
    rev_p_acc = [0] + list(accumulate(p[::-1]))
    print(
        (
            max(
                max(0, acc[k + i] - acc[i]) + p_acc[i] + rev_p_acc[n - k - i]
                for i in range(n - k + 1)
            )
        )
    )


if __name__ == "__main__":
    main()

-n, k, *a = list(map(int, open(0).read().split())) -p = [x if x > 0 else 0 for x in a] -acc = [0] + list(accumulate(a)) -p_acc = [0] + list(accumulate(p)) -rev_p_acc = [0] + list(accumulate(p[::-1])) -print( -    ( -        max( -            max(0, acc[k + i] - acc[i]) + p_acc[i] + rev_p_acc[n - k - i] -            for i in range(n - k + 1) + +def main(): +    n, k, *a = list(map(int, open(0).read().split())) +    p = [x if x > 0 else 0 for x in a] +    acc = [0] + list(accumulate(a)) +    p_acc = [0] + list(accumulate(p)) +    rev_p_acc = [0] + list(accumulate(p[::-1])) +    print( +        ( +            max( +                max(0, acc[k + i] - acc[i]) + p_acc[i] + rev_p_acc[n - k - i] +                for i in range(n - k + 1) +            ) -) + + +if __name__ == "__main__": +    main()