#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<ll> a(n+2),psum(n+2),ksum(n+2);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		psum[i] = psum[i-1] + max(a[i],0);
	}
	for(int i=1;i<=k;i++){
		ksum[1]+=a[i];
	}
	for(int i=k+1;i<=n;i++){
		ksum[i-k+1] = ksum[i-k] + a[i] - a[i-k];
	}
	ll ans=-1;
	for(int i=1;i<=n-k+1;i++){
		ll tmp=0;
		tmp += max(ksum[i],0);
		tmp += psum[i-1];
		tmp += psum[n] - psum[i+k-1];
		if(ans<tmp)ans=tmp;
	}
	cout<<ans<<endl;
	return 0;
}