#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, m, ans, a[N], mx[N], mx2[N], s[N];
int main()
{
	ll i;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		scanf ("%lld", &a[i]);
		s[i] = s[i - 1] + a[i];
		mx[i] = max(mx[i - 1], mx[i - 1] + a[i]);
	}
	for (i = n; i >= 1; i--) {
		mx2[i] = max(mx2[i + 1], mx2[i + 1] + a[i]);
	}
	for (i = 1; i <= n - m + 1; i++) {
		ans = max(ans, mx[i - 1] + mx2[i + m] + max(s[i + m - 1] - s[i - 1], 0ll));
	}
    cout << ans;
    return 0;
}
