#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
class BinaryIndexedTree {
  int N;
  std::vector<T> bit;

 public:
  BinaryIndexedTree(int n) : N(n), bit(n + 1, 0) {}
  void add(int index, T num) {
    for (int x = index; x <= N; x += x & -x) bit[x] += num;
  }
  T sum(int index) {
    int ret = 0;
    for (int x = index; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
  T sum(int left, int right) { return sum(right) - sum(left - 1); }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  BinaryIndexedTree<ll> BIT(n + 100), BIT2(n + 100);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    BIT.add(i + 1, a[i]);
    BIT2.add(i + 1, max(0LL, a[i]));
  }
  ll ans = 0;
  for (int i = n; i - k + 1 > 0; --i) {
    ll buf = BIT2.sum(i + 1, n) + BIT.sum(i - k + 1, i) + BIT2.sum(0, i - k);
    ans = max(ans, buf);
    buf = BIT2.sum(i + 1, n) + BIT2.sum(0, i - k);
    ans = max(ans, buf);
  }
  cout << ans << endl;
}
