#include <bits/stdc++.h>
template <typename T>
inline void rd(T& x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) {
  rd(x);
  rd(args...);
}
const int kN = 1e5 + 5;
long long a[kN], s[kN], f[kN], g[kN], h[kN];
int n, k;
int main() {
  rd(n, k);
  for (int i = 1; i <= n; ++i) rd(a[i]), s[i] = s[i - 1] + a[i];
  for (int i = 1; i <= n; ++i) {
    f[i] = f[i - 1] + a[i];
    if (i >= k) f[i] = std::max(f[i], g[i - 1] + s[i] - s[i - k]);
    g[i] = g[i - 1];
    if (i >= k) g[i] = std::max(g[i], f[i - 1] - s[i - 1] + s[i - k]);
    h[i] = g[i - 1] + a[i];
    if (i >= k) h[i] = std::max(h[i], g[i - 1] + s[i] - s[i - k]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans = std::max({ans, f[i], g[i], h[i]});
  printf("%lld", ans);
  return 0;
}
