#include <bits/stdc++.h>
using namespace std;
int IN() {
  int c, f, x;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
  while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0';
  return !f ? x : -x;
}
const int N = 100000 + 19;
long long A[N], S[N], f[N][2], g[N][2], res, tmp;
int n, k;
int main() {
  n = IN();
  k = IN();
  for (int i = 1; i < n + 1; i++) {
    A[i] = IN();
    S[i] = S[i - 1] + A[i];
  }
  for (int i = 1; i <= n; i++) {
    f[i][0] = f[i][1] = max(f[i - 1][0], f[i - 1][1]);
    f[i][1] += A[i];
  }
  for (int i = n; i >= 1; i--) {
    g[i][0] = g[i][1] = max(g[i + 1][0], g[i + 1][1]);
    g[i][1] += A[i];
  }
  for (int i = k; i <= n; i++) {
    tmp = max(tmp, f[i - k][0]);
    res = max(res, tmp + g[i + 1][0] + S[i] - S[i - k]);
  }
  tmp = 0;
  for (int i = k; i <= n; i++) {
    tmp = max(tmp, f[i - k][1]);
    res = max(res, tmp + g[i + 1][1]);
  }
  cout << res << endl;
}
