#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
ll N, K;
ll solve(vector<ll> A) {
  ll ans1 = 0;
  for (ll i = 0; i < N - K; i++) {
    if (A[i] > 0) {
      ans1 += A[i];
    }
  }
  ll ans2 = ans1;
  for (ll i = N - K; i < N; i++) {
    ans2 += A[i];
  }
  vector<ll> adds, subs;
  for (ll i = N - 1; i >= N - K; i--) {
    adds.push_back(max(0LL, A[i]));
    subs.push_back(max(0LL, A[i - K]));
  }
  for (ll i = 1; i < K; i++) {
    adds[i] += adds[i - 1];
    subs[i] += subs[i - 1];
  }
  ll addition = 0;
  for (ll i = 0; i < K; i++) {
    addition = max(addition, adds[i] - subs[i]);
  }
  return max(ans1 + addition, ans2);
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vector<ll> A(N);
  for (auto&& a : A) {
    cin >> a;
  }
  ll ans1 = solve(A);
  reverse(A.begin(), A.end());
  ll ans2 = solve(A);
  cout << max(ans1, ans2) << endl;
  return 0;
}
