#include<iostream>
#include<climits>
using namespace std;
typedef long long LL;
int n, m;
const int N = 300010;
int q[N], tt = 0, hh = 0;
LL s[N];
int main(){
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> s[i], s[i] = s[i - 1] + s[i];
LL res = INT_MIN;
for(int i = 1; i <= n; ++i)
{
if(i - q[hh] > m) hh++;
res = max(res, s[i] - s[q[hh]]);
while(hh <= tt && s[q[tt]] >= s[i]) tt--;
q[++tt] = i;
}
cout << res << endl;
return 0;
}