#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, K;
long long a[maxn], s[maxn], f[maxn][2], g[maxn][2];
int main() {
  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    f[i][0] =
        max({f[i - 1][0] + a[i],
             max(g[max(0, i - K - 1)][1], g[max(0, i - K - 1)][0]) + a[i]});
    f[i][1] = max(f[i - 1][1] + a[i], g[i - 1][0] + a[i]);
    g[i][0] = max(g[i - 1][0], f[i][0]);
    g[i][1] = max(g[i - 1][1], f[i][1]);
  }
  printf("%lld\n", max(g[n][0], g[n][1]));
  return 0;
}
