#include <bits/stdc++.h>
using namespace std;
long long N, K, A[100000];
int main(void) {
  cin >> N >> K;
  for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i];
  long long ans = 0, cnt = 0;
  for (long long i = ((long long)0); i < ((long long)N - K); i++) {
    if (A[i] > 0) {
      ans += A[i];
      cnt = 0;
    } else
      cnt++;
  }
  long long s = 0;
  for (long long i = ((long long)0); i < ((long long)cnt); i++)
    s += A[N - i - 1];
  long long m = s;
  for (long long i = ((long long)cnt); i < ((long long)min(K + cnt, N)); i++) {
    s += A[N - i - 1];
    m = max(m, s);
  }
  ans += m;
  cout << ans << endl;
}
