#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
template <typename T>
using PQ = priority_queue<T>;
using ll = long long;
using str = string;
template <typename T>
T sq(T a) {
  return a * a;
}
template <typename T, typename U>
void testP2(T a, U b) {
  cout << "(" << a << ", " << b << ")" << endl;
  return;
}
template <typename T>
void testV(T v) {
  cout << "[";
  for (auto i : v) {
    cout << i << ", ";
  }
  cout << "\b\b]" << endl;
  return;
}
template <typename T>
void testV2(T v) {
  for (auto sv : v) {
    testV(sv);
  }
  cout << endl;
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  V<ll> a(N);
  for (ll i = (0); i < (N); i++) {
    cin >> a[i];
  }
  ll sum = 0;
  for (ll i = (0); i < (K); i++) {
    sum += a[i];
  }
  ll maxid = 0, maxsum = sum;
  for (ll i = (0); i < (N - K); i++) {
    sum = sum - a[i] + a[i + K];
    if (sum > maxsum) {
      maxid = i + 1;
      maxsum = sum;
    }
  }
  ll ans1 = maxsum;
  for (ll i = (0); i < (N); i++) {
    if (i < maxid || maxid + K <= i) {
      ans1 += max(0LL, a[i]);
    }
  }
  ll pos = 0;
  for (ll i = (0); i < (K); i++) {
    if (a[i] > 0) {
      pos += a[i];
    }
  }
  ll minpos = pos, minid = 0;
  for (ll i = (0); i < (N - K); i++) {
    if (a[i] > 0) {
      pos -= a[i];
    }
    if (a[i + K] > 0) {
      pos += a[i + K];
    }
    if (pos < minpos) {
      minid = i + 1;
      minpos = pos;
    }
  }
  ll ans2 = 0;
  for (ll i = (0); i < (N); i++) {
    if (i < minid || minid + K <= i) {
      ans2 += max(0LL, a[i]);
    }
  }
  cout << max(ans1, ans2) << endl;
  return 0;
}
