#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> dp(n, 0);
  vector<int> dp_non_zero(n, 0);
  dp[0] = a[0];
  dp_non_zero[0] = max(a[0], 0);
  for (int i = 1; i < n; ++i) {
    dp[i] = dp[i - 1] + a[i];
    dp_non_zero[i] = dp_non_zero[i - 1] + max(a[i], 0);
  }
  int max_range = 0;
  for (int i = 0; i < n + 1 - k; ++i) {
    int temp1 = i != 0 ? dp_non_zero[i - 1] : 0;
    max_range =
        max(max_range, (dp[i + k - 1] - dp[i] + a[i]) + temp1 +
                           (dp_non_zero[n - 1] - dp_non_zero[i + k - 1]));
    max_range =
        max(max_range, temp1 + (dp_non_zero[n - 1] - dp_non_zero[i + k - 1]));
  }
  cout << max_range << endl;
  return 0;
}
