#include <bits/stdc++.h>
using namespace std;
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  static long long D[1 << 20];
  static long long s[1 << 20];
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  static int v[1 << 20];
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  long long ans = 0;
  ans = max(ans, accumulate(v + 1, v + 1 + n, 0ll));
  for (int cs = 0; cs < 2; ++cs) {
    reverse(v + 1, v + 1 + n);
    for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + v[i];
    for (int i = 1; i <= n; ++i) {
      D[i] = 0;
      D[i] = max(D[i], D[max(0, i - k)] + max(0ll, s[i] - s[max(0, i - k)]));
    }
    for (int i = 1; i <= n; ++i) D[i] = max(D[i], D[i - 1]);
    ans = max(ans, D[n]);
    long long cnt = 0;
    for (int i = n; i; --i) cnt = max(cnt, s[n] - s[i]);
    for (int i = n - k; i; --i)
      cnt = max(cnt, s[n] - s[i]), ans = max(ans, D[i] + cnt);
  }
  cout << ans << '\n';
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
