#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int(i) = 0; (i) < (int)(n); (i)++) cin >> a[i];
  vector<int> l(n, 0);
  vector<int> r(n, 0);
  vector<int> m(n, 0);
  l[0] = (a[0] > 0 ? a[0] : 0);
  r[n - 1] = (a[n - 1] > 0 ? a[n - 1] : 0);
  for (int i = 0; i < k; i++) m[0] += a[i];
  for (int i = 1; i <= n - k - 1; i++) l[i] = l[i - 1] + (a[i] > 0 ? a[i] : 0);
  for (int i = n - 2; i >= k; i--) r[i] = r[i + 1] + (a[i] > 0 ? a[i] : 0);
  for (int i = 1; i <= n - k; i++) m[i] = m[i - 1] - a[i - 1] + a[i + k - 1];
  int ans = -INF;
  amax(ans, (m[0] > 0 ? m[0] : 0) + r[k]);
  for (int i = 0; i <= n - k - 2; i++)
    amax(ans, l[i] + (m[i + 1] > 0 ? m[i + 1] : 0) + r[k + i + 1]);
  amax(ans, l[n - k - 1] + (m[n - k] > 0 ? m[n - k] : 0));
  cout << ans << endl;
  return 0;
}
