#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> a(100009);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = K; i <= N - 1 - K; i++) {
    if (a[i] > 0) sum += a[i];
  }
  long long suma = 0;
  long long ansa = 0;
  for (int i = K - 1; i >= 0; i--) {
    suma += a[i];
    ansa = max(suma, ansa);
  }
  sum += ansa;
  suma = 0;
  ansa = 0;
  for (int i = N - K; i < N; i++) {
    suma += a[i];
    ansa = max(suma, ansa);
  }
  sum += ansa;
  cout << sum << endl;
}
