#include <bits/stdc++.h>
using namespace std;
bool state[100005];
long long n, k;
long long a[100005], per_sum[100005];
int main() {
  cin >> n >> k;
  long long tmp = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    tmp += a[i];
    per_sum[i] = tmp;
  }
  memset(state, true, sizeof(state));
  for (long long i = 0; i <= n - k; i++) {
    long long sum = 0;
    if (i == 0)
      sum = per_sum[i + k - 1];
    else
      sum = per_sum[i + k - 1] - per_sum[i - 1];
    if (sum >= 0) {
      for (long long j = i - 1; j >= 0; j--) {
        if (a[j] >= 0) break;
        state[j] = false;
      }
      for (long long j = i + k; j < n; j++) {
        if (a[j] >= 0) break;
        state[j] = false;
      }
    }
  }
  for (long long i = 0; i <= n - k; i++) {
    bool ok = true;
    for (long long j = i; j < i + k; j++)
      if (a[j] > 0) {
        ok = false;
        break;
      }
    if (ok)
      for (long long j = i; j < i + k; j++) state[j] = false;
  }
  long long res = 0;
  for (long long i = 0; i < n; i++) res += (long long)(state[i] * a[i]);
  if (res < 0) res = 0;
  cout << res << endl;
  return 0;
}
