#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 9;
long long a[N];
long long pf[N];
long long best[N];
int n, k;
long long solve() {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum = max(sum, sum + a[i]);
    pf[i] = sum;
  }
  long long tot = 0;
  for (int i = n; i > n - k; i--) {
    tot += a[i];
  }
  best[n + 1] = max(0ll, tot);
  long long suf = 0;
  for (int i = n; i > n - k; i--) {
    suf += a[i];
    best[i] = max(best[i + 1], suf);
  }
  long long ret = 0;
  for (int i = 0; i <= n - k; i++) {
    ret = max(ret, pf[i] + best[i + k + 1]);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long s1 = solve();
  reverse(a + 1, a + n + 1);
  long long s2 = solve();
  cout << max(s1, s2) << "\n";
  return 0;
}
