from itertools import accumulate
n, k = map(int, input().split())
a = list(map(int, input().split()))


left_sum = [0 for i in range(n+1)]
sum_value = 0
for i in range(n):
    if a[i] > 0:
        sum_value += a[i]
    left_sum[i+1] = sum_value


c = list(accumulate(a))
range_sum = [0 for i in range(n-k+1)]
range_sum[0] = max(c[k-1], 0)
for i in range(1, n-k+1):
    range_sum[i] = max(c[i+k-1] - c[i-1], 0)


a.reverse()


right_sum = [0 for i in range(n+1)]
sum_value = 0
for i in range(n):
    if a[i] > 0:
        sum_value += a[i]
    right_sum[i+1] = sum_value


ans = 0
for i in range(n-k+1):
    ans = max(ans, left_sum[i] + range_sum[i] + right_sum[n-k-i])
print(ans)