#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+1;
ll a[N],n,k,dp[N],p[N];
deque <int> d;
int main() {
    freopen("RONGTHAN.INP","r",stdin);
    freopen("RONGTHAN.OUT","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k,k--;
    for(int i=1;i<=n;i++) cin >> a[i], p[i]=p[i-1]+a[i];
    d.push_back(0), dp[1]=a[1];
    for(int i=2;i<=n;i++) {
        while(!d.empty() && dp[d.back()]+p[i]-p[d.back()+1]<=a[i]+dp[i-2]) d.pop_back();
        d.push_back(i-2);
        if(d.front()==i-k-2) d.pop_front();
        dp[i]=max(dp[i-1],dp[d.front()]+p[i]-p[d.front()+1]);
        if(i<=k) dp[i]=p[i];
    }
    cout << *max_element(dp+1,dp+n+1);
    return 0;
}
