#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, k;
int a[maxn], b[maxn], e[maxn];
long long sum[maxn], ans;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    if (a[i] > 0) b[i] = 1;
    sum[i] = sum[i - 1] + a[i];
    e[i] = e[i - 1] + b[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1 && sum[i + k - 1] - sum[i - 1] >= 0) {
      for (int j = i; j <= i + k - 1; ++j) b[j] = 1;
      i += k - 1;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (b[i] == 1) ans += a[i];
  printf("%lld", ans);
  return 0;
}
