#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int NN = 20;
const int INF = 1e9 + 7;
int n, k;
long long a[N], dp[N], pref[N];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
  }
  if (k + k > n) {
    for (int i = 1; i <= n; i++) {
      if (i < k) continue;
      dp[i] = max(dp[i - 1], dp[i - k] + pref[i] - pref[i - k]);
    }
    cout << dp[n];
    return 0;
  }
  long long ans = 0;
  for (int i = k + 1; i <= n - k; i++) {
    if (a[i] > 0) {
      ans += a[i];
    }
  }
  long long sum = 0, mx = 0;
  for (int i = 1; i <= k; i++) {
    sum += a[i];
    mx = max(mx, sum);
  }
  ans += mx;
  sum = mx = 0;
  for (int i = n; i >= n - k + 1; i--) {
    sum += a[i];
    if (sum > 0) {
      mx = max(mx, sum);
    }
  }
  ans += mx;
  cout << ans;
  return 0;
}
