#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool maxup(T& a, T&& b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T>
bool maxup(T& a, T& b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T>
bool minup(T& a, T&& b) {
  if (a > b) {
    a = b;
    return true;
  };
}
template <typename T>
bool minup(T& a, T& b) {
  if (a > b) {
    a = b;
    return true;
  };
}
using VV = vector<vector<long long>>;
using V = vector<long long>;
using P = pair<long long, long long>;
using IP = pair<long long, P>;
template <typename T>
inline void input(vector<T>& v) {
  for (auto& x : v) cin >> x;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  V v(n);
  input(v);
  V like(n + 1);
  V sum(n + 1);
  for (signed i = signed(0); i < signed(n); i++) {
    like[i + 1] = max(like[i], like[i] + v[i]);
    sum[i + 1] += sum[i] + v[i];
  }
  long long ans = like[n - k];
  for (signed i = signed(1); i < signed(n - k + 1); i++) {
    maxup(ans,
          like[i] + max(0ll, sum[i + k] - sum[i]) + (like[n] - like[i + k]));
  }
  cout << ans << endl;
}
