# include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
const int maxn = 100010;
#define pb push_back

int a[maxn];

long long s[maxn];
long long f[maxn];
long long g[maxn];

int main() {
	int n, K; scanf("%d%d", &n, &K);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		s[i] = s[i-1] + a[i];
		f[i] = f[i-1] + max(a[i], 0);
		if(i == K) {
			g[i] = max(s[i], 0ll);
		} else {
			g[i] = f[i-K] + max(s[i] - s[i-K], 0ll);
			g[i] = max(g[i], g[i-1] + max(a[i], 0));
		}
	}
	printf("%lld\n", g[n]);
	return 0;
}
