#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T> &v) {
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
template <typename T>
inline istream &operator>>(istream &i, vector<T> &v) {
  for (int j = 0; j < (int)((int)v.size()); j++) i >> v[j];
  return i;
}
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;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {
  return i >= 0 && i < h && j >= 0 && j < w;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void err() { cout << -1 << endl; }
const int MOD = 1000000007;
const int INF = 1e9;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  V<> a(n);
  cin >> a;
  do {
    std::cout << "a"
              << " : ";
    view(a);
  } while (0);
  V<ll> sum(n + 1, 0);
  for (int i = 0; i < (int)(n); i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  V<ll> l(n + 1, 0);
  V<ll> r(n + 1, 0);
  for (int i = 0; i < (int)(n); i++)
    if (a[i] > 0)
      l[i + 1] = l[i] + a[i];
    else
      l[i + 1] = l[i];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] > 0)
      r[i] = r[i + 1] + a[i];
    else
      r[i] = r[i + 1];
  }
  ll ans = 0;
  for (int i = 0; i < (int)(n - k + 1); i++) {
    chmax(ans, l[i] + (sum[i + k] - sum[i]) + r[i + k]);
    chmax(ans, l[i] + r[i + k]);
  }
  cout << ans << endl;
}
