#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
using namespace std;
const int N = 2 * 1e5 + 10;
int tot  , n , ans , x , a[N] , pr[N] , dp[N]; 

bool was[N];
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	
	cin >> n >> x;
	/* a[i] > 0
	ls
	1 2 3 4 5 6 	
	*/
	int ls = 0;
	rep(i , 1 , n + 1){
		cin >> a[i];
	}
	int l = 1;
	#define const asda
	int const = 0;
	while(1){
		int r = l;
		while(a[r] <= 0 && r <= n)
			r++;
		if(r - l >= x)
			for(int i = l ; i < r ; i++)
				a[i] = 0;
		l = r;
		while(a[l] >= 0 && l <= n)	
			l++;
		
		if(l - r >= x)
			for(int i = r ; i < l ;i++)
				const += a[i] , a[i] = 0;
		if(l > n)
			break;
	}
	/*for(int i = 1 ; i <= n ; i++)
		cout << a[i] << ' ';*/
	for(int i = 1 ; i <= n ; i++){
		pr[i] = pr[i - 1] + a[i];
		if(i - x >= 0)
		dp[i] = max(dp[i - 1] , dp[i - x] + pr[i] - pr[i - x]);
	}
	
	for(int i = 1 ; i <= n ; i++)
		ans = max(ans , dp[i]);
	cout << ans + const;
	/*       a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 ... an*/
}