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

signed main(){
	int n,k,a[100000],ma = 0,x = 0,y = 0;
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n - k;i++) x += max(0ll,a[i]);
	for(int i = n - k;i < n;i++) y += a[i];
	ma = max(ma,x + max(0ll,y));
	for(int i = 0;i < n - k;i++){
		x += max(0ll,a[n - i - 1]) - max(0ll,a[n - k - 1 - i]);
		y += a[n - k - 1 - i] - a[n - i - 1];
		ma = max(ma,x + max(0ll,y));
	}
	cout << ma << endl;
	return 0;
}