#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int seg[400005];
int pre[100005];

void build(int ver,int tl,int tr)
{
	if(tl>tr)
		return ;
	else if(tl==tr)
	{
		seg[ver]=-1e17;
	}
	else
	{
		int tm=(tl+tr)/2;
		build(2*ver,tl,tm);
		build(2*ver+1,tm+1,tr);
		seg[ver]=max(seg[2*ver],seg[2*ver+1]);
	}	
}

void upd(int ver,int tl,int tr,int pos,int val)
{
	if(tl>tr)
		return ;
	else if(tl==tr)
		seg[ver]=max(seg[ver],val);
	else
	{
		int tm=(tl+tr)/2;
		if(tm>=pos)
			upd(2*ver,tl,tm,pos,val);
		else
			upd(2*ver+1,tm+1,tr,pos,val);
		seg[ver]=max(seg[2*ver],seg[2*ver+1]);
	}
}

int get(int ver,int tl,int tr,int l,int r)
{
	if(tl>tr||l>r||tr<l||r<tl)
		return -1e17;
	else if(tl==l&&tr==r)
		return seg[ver];
	else
	{
		int tm=(tl+tr)/2;
		return max(get(2*ver,tl,tm,l,min(tm,r)),get(2*ver+1,tm+1,tr,max(tm+1,l),r));
	}
}

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
	if(fopen("INPUT.txt","r"))
	{
	freopen ("INPUT.txt" , "r" , stdin);
	freopen ("OUTPUT.txt" , "w" , stdout);
	}
#endif  

	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		pre[i]=pre[i-1]+a[i];
	}
	for(int i=1;i<=k;i++)
	{
		upd(1,1,n,i,pre[i]);
	}

	for(int i=k+1;i<=n;i++)
	{
		int z=get(1,1,n,i-1,i-1);
		upd(1,1,n,i,z+a[i]);
		z=get(1,1,n,1,i-k);
		z=max(z,0LL);		
		upd(1,1,n,i,z+pre[i]-pre[i-k]);
		z=get(1,1,n,1,i-k);
		z=max(z,0LL);
		upd(1,1,n,i,z+a[i]);
	}
	int mx=0;
	mx=max(mx,get(1,1,n,k,n));
	for(int i=1;i<=k-1;i++)
	{
		if(n-i>=k)
		{
			mx=max(mx,pre[i]);
		}
	}
	cout<<mx;
}
