#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long tmp, x;
  x = 0;
  long long a[100001] = {};
  long long b[100001] = {};
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
    if (i < k)
      a[i] = a[i - 1] + tmp;
    else
      a[i] = a[i - 1] + tmp - v[i - k];
    if (v[i] > 0)
      b[i + 1] = b[i] + v[i];
    else
      b[i + 1] = b[i];
  }
  long long dp[100001] = {};
  for (int i = 0; i < k; i++) {
    x += v[i];
  }
  if (x > 0) dp[k] = x;
  for (int i = k; i < n; i++) {
    dp[i + 1] = max(dp[i], v[i - k] + dp[i - k + 1]);
    dp[i + 1] = max(dp[i + 1], a[i] + b[i - k]);
    dp[i + 1] = max(v[i] + dp[i], dp[i + 1]);
  }
  cout << dp[n] << endl;
  return 0;
}
