#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n, 0);
  long long tmp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  long long msum = 0;
  for (int i = 0; i < k; i++) {
    msum += a[i];
  }
  long long rsum = 0;
  for (int i = 0; i < k; i++) {
    rsum += max((long long)0, a[n - k + i]);
  }
  long long lsum = 0;
  for (int i = 0; i < n - k; i++) {
    msum -= a[i];
    msum += a[k + i];
    if (a[i] > 0) {
      lsum += a[i];
    }
    if (a[i + k] > 0) {
      rsum -= a[i + k];
    }
    sum = max(sum, max(msum, (long long)0) + rsum + lsum);
  }
  cout << sum;
  return 0;
}
