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