#include<iostream>#include<cstring>#include<algorithm>#include<climits>usingnamespace std;typedeflonglong LL;constint N =3e5+6;int q[N];
LL s[N];intmain(){
int n, m;scanf("%d %d",&n,&m);for(int i =1; i <= n; i ++){
scanf("%lld",&s[i]);
s[i]+= s[i-1];}memset(q,0,sizeof q);
LL res = INT_MIN;int hh =0, tt =0;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;}printf("%lld", res);return0;}