1 #include <iostream>
2 #include <cstdio>
3 #include <cmath>
4 #include <cstring>
5 #include <cmath>
6 #define inf 999999999999999999LL
7 #define N 100000+1000
8 #define ll long long
9 using namespace std;
10 struct data
11 {
12 int p;
13 ll v;
14 }q[N];
15 int a[N];
16 int n,k,l,r;
17 ll minn,ans,f[N];
18 inline int read()
19 {
20 int f=1,ans=0;
21 char c;
22 while (!isdigit(c=getchar())) if (c==‘-‘) f=-1;
23 ans=c-‘0‘;
24 while (isdigit(c=getchar())) ans=ans*10+c-‘0‘;
25 return ans*f;
26 }
27 int main()
28 {
29 n=read(); k=read();
30 for (int i=1;i<=n;i++)
31 {
32 a[i]=read();
33 ans+=a[i];
34 }
35 //l=; r=0;
36 for (int i=1;i<=n;i++)
37 {
38 f[i]=q[l].v+a[i];
39 while (l<=r && q[r].v>f[i]) r--;
40 q[++r].v=f[i];
41 q[r].p=i;
42 while (q[l].p<i-k) l++;
43 }
44 minn=inf;
45 for (int i=n-k;i<=n;i++) minn=min(minn,f[i]);
46 printf("%lld\n",ans-minn);
47 return 0;
48 }