#include <bits/stdc++.h>
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> data(n), left(n + 1, 0), right(n + 1, 0);
  for (int i = 0; i < (n); i++) cin >> data[i];
  for (int i = 0; i < (n); i++) left[i + 1] = left[i] + max(0ll, data[i]);
  for (int i = 0; i < (n); i++)
    right[i + 1] = right[i] + max(0ll, data[n - 1 - i]);
  ll count = 0;
  for (int i = 0; i < (k); i++) count += data[i];
  ll ans = count + left[0] + right[n - k];
  for (int i = 0; i < (n - k); i++) {
    count += data[k + i];
    count -= data[i];
    chmax(ans, max(0ll, count) + left[1 + i] + right[n - k - 1 - i]);
  }
  cout << ans << endl;
}
