#include <bits/stdc++.h>
using namespace std;
vector<long long> sum(100001);
int n, k, x[100001];
long long Sum(int i) { return sum[i + k] - sum[i]; }
long long Sum(int l, int r) { return sum[r + 1] - sum[l]; }
long long dfs2(int);
long long mem[100001], used[100001];
long long dfs(int idx) {
  if (idx + k > n) return 0;
  if (used[idx]++) return mem[idx];
  long long res = x[idx] > 0 ? x[idx] + dfs(idx + 1) : dfs(idx + 1);
  res = max(res, Sum(idx) + dfs(idx + k));
  res = max(res, Sum(idx, n - 1) - dfs2(idx));
  return mem[idx] = res;
}
long long mem2[100001], used2[100001];
long long dfs2(int idx) {
  if (idx + k > n) return 0;
  if (used2[idx]++) return mem2[idx];
  long long res = x[idx] < 0 ? x[idx] + dfs2(idx + 1) : dfs2(idx + 1);
  res = min(res, Sum(idx) + dfs2(idx + k));
  return mem2[idx] = res;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> x[i], sum[i + 1] += x[i] + sum[i];
  long long ans = dfs(0);
  ans = max(ans, sum[n] - dfs2(0));
  cout << ans << endl;
  return 0;
}
