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

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



ans = sum([a for a in A if a > 0])

B = [a if a <= 0 else 0 for a in A]



s = sum(B[:K])

s_max = s

c = sum([1 for a in A[:K] if a <= 0])

c_max = c

for i in range(N-K):

  s += B[i+K] - B[i]

  s_max = max(s_max, s)

  c += (A[i+K]<=0) - (A[i]<=0)

  c_max = max(c_max, c)



if c_max == K:

  print(ans)

  quit()



B = [a if a > 0 else 0 for a in A]

s = sum(B[:K])

s_min = s

for i in range(N-K):

  s += B[i+K] - B[i]

  s_min = min(s_min, s)



print((max(ans+s_max, ans-s_min)))
N, K = list(map(int, input().split()))

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



ans = sum([a for a in A if a > 0])

B = [a if a <= 0 else 0 for a in A]



s = sum(B[:K])

s_max = s

for i in range(N-K):

  s += B[i+K] - B[i]

  s_max = max(s_max, s)



B = [a if a > 0 else 0 for a in A]

s = sum(B[:K])

s_min = s

for i in range(N-K):

  s += B[i+K] - B[i]

  s_min = min(s_min, s)



print((max(ans+s_max, ans-s_min)))
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
c = sum([1 for a in A[:K] if a <= 0])
c_max = c
for i in range(N - K):
    s += B[i + K] - B[i]
    s_max = max(s_max, s)
    c += (A[i + K] <= 0) - (A[i] <= 0)
    c_max = max(c_max, c)
if c_max == K:
    print(ans)
    quit()
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N - K):
    s += B[i + K] - B[i]
    s_min = min(s_min, s)
print((max(ans + s_max, ans - s_min)))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
for i in range(N - K):
    s += B[i + K] - B[i]
    s_max = max(s_max, s)
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N - K):
    s += B[i + K] - B[i]
    s_min = min(s_min, s)
print((max(ans + s_max, ans - s_min)))

-c = sum([1 for a in A[:K] if a <= 0]) -c_max = c -    c += (A[i + K] <= 0) - (A[i] <= 0) -    c_max = max(c_max, c) -if c_max == K: -    print(ans) -    quit()