#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, p, k, a[100005], K;
long long f[100005], g[100005], M1, M2, sum[100005], ans, F[100005], G[100005];
int main() {
  scanf("%d%d", &n, &K);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
  M1 = M2 = 0;
  for (i = 1; i <= n; ++i) {
    f[i] = M1 + sum[i];
    g[i] = M2;
    M1 = max(M1, g[i] - sum[i]);
    M2 = max(M2, f[i]);
  }
  M1 = 0 + sum[n];
  M2 = 0;
  for (i = n; i >= 1; --i) {
    F[i] = M1 - sum[i - 1];
    G[i] = M2;
    M1 = max(M1, G[i] + sum[i]);
    M2 = max(M2, F[i]);
  }
  for (i = 1; i <= n; ++i)
    if (i + K - 1 <= n)
      ans = max(ans, max(f[i - 1], g[i - 1]) + sum[i + K - 1] - sum[i - 1] +
                         max(G[i + K], F[i + K]));
  cout << ans << endl;
}
