#include <bits/stdc++.h>
using namespace std;
const int dh[8] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dw[8] = {0, 0, 1, -1, 1, -1, 1, -1};
vector<int> his;
int main() {
  int n, k;
  cin >> n;
  cin >> k;
  long long bests = 0;
  long long diffs = 0;
  vector<long long> a(n);
  vector<long long> best(n);
  vector<long long> diff(n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    a[i] = num;
    if (num > 0) ans += num;
    if (i < k) {
      if (num > 0) {
        bests += num;
      }
      best[i] = bests;
      diffs += num;
      diff[i] = diffs;
    } else {
      if (num > 0) {
        bests += num;
        if (a[i - k] > 0) {
          bests -= a[i - k];
        }
      }
      best[i] = bests;
      diffs += (num - a[i - k]);
      diff[i] = diffs;
    }
  }
  long long mindiff = 9223372036854775807;
  for (int i = k - 1; i < n; i++) {
    mindiff = min(mindiff, min(best[i], best[i] - diff[i]));
  }
  cout << ans - mindiff << endl;
  return 0;
}
