#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=10000000+7;
long long a[maxn],n,k,chsec,nesec;
long long ans,pl[maxn],mi[maxn],chos=0x7f7f7f7f,nein=0x7f7f7f7f;
bool flag;
int main()
{
	freopen("Data.txt","r",stdin);
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
		pl[i]=pl[i-1];	mi[i]=mi[i-1];
		if(a[i]>0)pl[i]+=a[i];	else mi[i]+=abs(a[i]);
	}
	for(int i=k;i<=n;++i)
	{
		if(mi[i]-mi[i-k]<chos)
		{chsec=i-k;	chos=mi[i]-mi[i-k];}
		if(pl[i]-pl[i-k]<nein)
		{nesec=i-k;	nein=pl[i]-pl[i-k];}
	}
	if(chos>nein)flag=true;
	for(int i=1;i<=n;++i)
	{
		if(flag){
			if(i>nesec && i<=nesec+k)continue;
			else if(a[i]>0)ans+=a[i];
		}
		else{
			if(i>chsec && i<=chsec+k)ans+=a[i];
			else if(a[i]>0)ans+=a[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}