1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cstdlib>
5 #include<cmath>
6 #include<algorithm>
7 #define LL long long
8 using namespace std;
9 int n,m;
10 LL a[100005];
11 LL f[100005];
12 struct data {
13 LL val,w;
14 }q[100005];
15 int main(){
16 LL sum=0;
17 scanf("%d%d",&n,&m);
18 for(int i=1;i<=n;i++){scanf("%lld",&a[i]);sum+=a[i];}
19 int h=0,t=1;
20 q[0].w=0;q[0].val=0;
21 for(int i=1;i<=n;i++) {
22 while(h<t&&q[h].w<i-m-1) h++;
23 f[i]=q[h].val+a[i];
24 while(f[i]<q[t-1].val&&h<t) t--;
25 q[t++]=(data){f[i],i};
26 }
27 LL ans=1LL<<60;
28 for(int i=n;i>=n-m;i--) ans=min(ans,f[i]);
29 printf("%lld",sum-ans);
30 return 0;
31 }