#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
const ld EPS = 1e-9;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const ll MOD = 1e9 + 7;
using cd = complex<double>;
void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
bool close_dbl(ld a, ld b) { return abs(a - b) < EPS; }
struct pt {
  ll x, y, z;
};
pt operator-(const pt &fi, const pt &se) {
  return {fi.x - se.x, fi.y - se.y, fi.z - se.z};
}
pt cross(const pt &fi, const pt &se) {
  return {fi.y * se.z - fi.z * se.y, -(fi.x * se.z - fi.z * se.x),
          fi.y * se.z - fi.z * se.y};
}
int dumb(vector<pt> pts) {
  int n = pts.size();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int e = i + 1; e < n; ++e) {
      pt cock = pts[e] - pts[i];
      int cur = 0;
      for (int j = 0; j < n; ++j) {
        auto vv = cross(cock, pts[j] - pts[i]);
        cur += (vv.x == 0) && (vv.y == 0) && (vv.z == 0);
      }
      ans = max(ans, cur);
    }
  }
  return ans;
}
signed main() {
  auto solve = [](int _) {
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    vector<int> pref_pos(n + 1);
    vector<int> suff_pos(n + 2);
    for (int i = 1; i <= n; ++i) {
      pref_pos[i] = pref_pos[i - 1];
      if (a[i] > 0) {
        pref_pos[i] += a[i];
      }
    }
    suff_pos.back() = max(a.back(), 0);
    for (int i = n - 1; i >= 1; --i) {
      suff_pos[i] = suff_pos[i + 1];
      if (a[i] > 0) {
        suff_pos[i] += a[i];
      }
    }
    vector<ll> pref(n + 1);
    for (int i = 1; i <= n; ++i) {
      pref[i] = pref[i - 1] + a[i];
    }
    ll ans = 0;
    for (int i = 1; i + k - 1 <= n; ++i) {
      ll cur = pref[i + k - 1] - pref[i - 1];
      ans = max(ans, max<ll>(cur, 0ll) + pref_pos[i - 1] + suff_pos[i + k]);
    }
    cout << ans;
  };
  fast_io();
  cout.precision(9);
  cout << fixed;
  auto start = chrono::steady_clock::now();
  auto end = chrono::steady_clock::now();
  solve(1);
  42;
}
