#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template <typename T, typename... U>
inline void read(T& x, U&... y) {
  read(x), read(y...);
}
int n, K;
long long A[100010], L[100010], R[100010], S[100010];
int main() {
  read(n, K);
  for (int i = 1; i <= n; ++i) read(A[i]), S[i] = S[i - 1] + A[i];
  for (int i = 1; i <= n; ++i) {
    L[i] = L[i - 1];
    if (A[i] > 0) L[i] += A[i];
  }
  for (int i = n; i; --i) {
    R[i] = R[i + 1];
    if (A[i] > 0) R[i] += A[i];
  }
  long long res = 0;
  for (int i = 0; i <= n - K; ++i)
    res = max(res, L[i] + R[i + K + 1] + max(0ll, S[i + K] - S[i]));
  for (int i = n; i > K; --i) L[i] = L[i - K] + S[i] - S[i - K];
  for (int i = 1; i <= K; ++i) L[i] = S[i];
  for (int i = 1; i <= n; ++i) L[i] = max(L[i], L[i - 1]);
  for (int i = 1; i <= n - K; ++i) R[i] = R[i + K] + S[i + K - 1] - S[i - 1];
  for (int i = n - K + 1; i <= n; ++i) R[i] = S[n] - S[i - 1];
  for (int i = n; i; --i) R[i] = max(R[i], R[i + 1]);
  for (int i = 1; i <= n; ++i) res = max(res, L[i] + R[i + 1]);
  printf("%lld\n", res);
  return 0;
}
