Problem:
Score : 400 points

Problem Statement

There are N squares aligned in a row.
The i-th square from the left contains an integer a_i.

Initially, all the squares are white.
Snuke will perform the following operation some number of times:

Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares are overwritten.

After Snuke finishes performing the operation, the score will be calculated as the sum of the integers contained in the black squares.
Find the maximum possible score.

Constraints

1≤N≤10^5

1≤K≤N

a_i is an integer.

|a_i|≤10^9

Input

The input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the maximum possible score.

Sample Input 1

5 3
-10 10 -10 10 -10

Sample Output 1

10

Paint the following squares black: the second, third and fourth squares from the left.

Sample Input 2

4 2
10 -10 -10 10

Sample Output 2

20

One possible way to obtain the maximum score is as follows:

Paint the following squares black: the first and second squares from the left.

Paint the following squares black: the third and fourth squares from the left.

Paint the following squares white: the second and third squares from the left.

Sample Input 3

1 1
-10

Sample Output 3

0

Sample Input 4

10 5
5 -4 -5 -8 -4 7 2 -4 0 7

Sample Output 4

17

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll a[100010];
ll sum[100010];

int main()
{
	bool flag = false;
	int checkA = 0,checkB = 0;
	ll ret = 0;
	
	ll n,k;cin >> n >> k;
	REP(i,n)
	{
		cin >> a[i+1];
		sum[i+1] = sum[i] + a[i+1];
		if(a[i+1] > 0)
		{
			checkB= 0;
			checkA++;ret+=a[i+1];
		}
		else if(a[i+1] < 0)
		{
			checkA = 0;
			checkB--;
		}
		else{checkA++;checkB++;}
		if(checkA == k || checkB == k)flag = true;
	}
	
	if(flag)
	{
		cout << ret << endl;
		return 0;
	}
	
	pair<pair<int,int>,ll> ma = MP(MP(0,0),-1000000000000000);
	pair<pair<int,int>,ll> mi = MP(MP(0,0),1000000000000000);
	
	REP(i,n-k+1)
	{
		ll tmp = sum[i+k] - sum[i];
		if(ma.SE < tmp)
		{
			ma.SE = tmp;
			ma.FI.FI = i+1;
			ma.FI.SE = i+k;
		}
		if(mi.SE > tmp)
		{
			mi.SE = tmp;
			mi.FI.FI = i+1;
			mi.FI.SE = i+k;
		}
	}
	
	ll ans = -1000000000000000;
	ll hi = 0;
	for(int i= 1;i <= n;i++)
	{
		if(i < ma.FI.FI || i > ma.FI.SE)
		{
			if(a[i] > 0)hi += a[i];
		}
		else
		{
			hi += a[i];
		}
	}
	ans = max(ans,hi);hi = 0;
	for(int i = 1;i <= n;i++)
	{
		if(i < mi.FI.FI || i > mi.FI.SE)
		{
			if(a[i] > 0)hi += a[i];
		}
	}
	ans = max(ans,hi);
	//cout << ma.FI.FI << ' ' << ma.FI.SE << endl;
	//cout << mi.FI.FI << ' ' << mi.FI.SE << endl;
	
	cout << max(ans,0ll) << endl;
	
	return 0;
}