#include <bits/stdc++.h>
using namespace std;
int N, K, a[100000];
int main() {
  cin >> N >> K;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N - K; i++) {
    if (a[i] > 0) {
      ans += a[i];
    }
  }
  long long resid_max = 0;
  long long resid_all = 0;
  for (int k = 1; k <= K; k++) {
    resid_all += a[N - k];
  }
  if (resid_all > resid_max) resid_max = resid_all;
  long long tmp = 0;
  for (int k = 1; k <= K - 1; k++) {
    tmp += a[N - k];
    if (a[N - K - k] > 0) {
      tmp -= a[N - K - k];
    }
    if (tmp > resid_max) {
      resid_max = tmp;
    }
  }
  cout << ans + resid_max << endl;
}
