#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline string IntToString(long long a) {
  char x[100];
  sprintf(x, "%lld", a);
  string s = x;
  return s;
}
inline long long StringToInt(string a) {
  char x[100];
  long long res;
  strcpy(x, a.c_str());
  sscanf(x, "%lld", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
class SegmentTree {
 public:
  long long prop[800005];
  long long val[800005];
  void build() {
    memset(prop, 0, sizeof(prop));
    memset(val, 0, sizeof(val));
  }
  void push(int ix, int L, int R) {
    val[ix * 2 + 1] += prop[ix];
    val[ix * 2 + 2] += prop[ix];
    prop[ix * 2 + 1] += prop[ix];
    prop[ix * 2 + 2] += prop[ix];
    prop[ix] = 0;
  }
  void update(int ix, int L, int R, int x, int y, long long v) {
    if (x <= L && R <= y) {
      val[ix] += v;
      prop[ix] += v;
      return;
    }
    if (R < x || y < L) return;
    push(ix, L, R);
    int M = (L + R) >> 1;
    update(ix * 2 + 1, L, M, x, y, v);
    update(ix * 2 + 2, M + 1, R, x, y, v);
    val[ix] = max(val[ix * 2 + 1], val[ix * 2 + 2]);
  }
  long long query(int ix, int L, int R, int x, int y) {
    if (x <= L && R <= y) return val[ix];
    if (R < x || y < L) return -INFF;
    push(ix, L, R);
    int M = (L + R) >> 1;
    return max(query(ix * 2 + 1, L, M, x, y),
               query(ix * 2 + 2, M + 1, R, x, y));
  }
};
int n, k;
int data[100005];
long long sum[100005];
int last = -INF;
long long risan = 0;
long long dp[100005];
SegmentTree hitam, putih;
long long jum(int a, int b) { return (a == 0 ? sum[b] : sum[b] - sum[a - 1]); }
int main() {
  putih.build();
  hitam.build();
  scanf("%d %d", &n, &k);
  for (int(i) = (0); (i) < (n); ++(i)) {
    scanf("%d", &data[i]);
    sum[i] = (i == 0 ? 0 : sum[i - 1]);
    sum[i] += data[i];
  }
  if (k == 1) {
    for (int(i) = (0); (i) < (n); ++(i)) risan += (data[i] >= 0 ? data[i] : 0);
    printf("%lld\n", risan);
    return 0;
  }
  for (int(i) = (0); (i) < (n); ++(i)) risan += data[i];
  for (int(i) = (n - k + 1); (i) < (n); ++(i)) {
    hitam.update(0, 0, n, i, i, -INFF);
    putih.update(0, 0, n, i, i, -INFF);
  }
  for (int(i) = (n - k); (i) >= (0); --(i)) {
    putih.update(0, 0, n, i + 1, i + k - 1, -data[i]);
    long long res1 = -hitam.query(0, 0, n, i + 1, i + k - 1);
    long long res2 = -putih.query(0, 0, n, i + 1, i + k - 1);
    dp[i] = jum(i, i + k - 1);
    dp[i] = min(dp[i], min(res1, res2));
    hitam.update(0, 0, n, i, i, -dp[i]);
    putih.update(0, 0, n, i, i, -dp[i]);
  }
  risan -= dp[0];
  putih.build();
  hitam.build();
  for (int(i) = (n - k + 1); (i) < (n); ++(i)) {
    hitam.update(0, 0, n, i, i, -INFF);
    putih.update(0, 0, n, i, i, -INFF);
  }
  for (int(i) = (n - k); (i) >= (0); --(i)) {
    hitam.update(0, 0, n, i + 1, i + k - 1, data[i]);
    long long res1 = hitam.query(0, 0, n, i + 1, i + k - 1);
    long long res2 = putih.query(0, 0, n, i + 1, i + k - 1);
    dp[i] = jum(i, i + k - 1);
    dp[i] = max(dp[i], max(res1, res2));
    hitam.update(0, 0, n, i, i, dp[i]);
    putih.update(0, 0, n, i, i, dp[i]);
  }
  printf("%lld\n", max(risan, dp[0]));
  return 0;
}
