#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll leftans = 0;
  ll lastwhite = 0;
  for (int i = 0; i < n - k; i++) {
    if (a[i] > 0) {
      leftans += a[i];
      lastwhite = i + 1;
    }
  }
  ll lefttemp = 0;
  for (int i = n - k; i < n; i++) {
    lefttemp += a[i];
  }
  ll lefttemptemp = 0;
  for (int i = n - 1; i >= lastwhite + k; i--) {
    if (a[i] > 0) {
      lefttemptemp += a[i];
    }
  }
  if (max(lefttemp, lefttemptemp) > 0) {
    leftans += max(lefttemp, lefttemptemp);
  }
  ll rightans = 0;
  lastwhite = n - 1;
  for (int i = n - 1; i >= k; i--) {
    if (a[i] > 0) {
      rightans += a[i];
      lastwhite = i - 1;
    }
  }
  ll righttemp = 0;
  for (int i = k - 1; i >= 0; i--) {
    righttemp += a[i];
  }
  ll righttemptemp = 0;
  for (int i = 0; i <= lastwhite - k; i++) {
    if (a[i] > 0) {
      righttemptemp += a[i];
    }
  }
  if (max(righttemp, righttemptemp) > 0) {
    rightans += max(righttemp, righttemptemp);
  }
  cout << max(leftans, rightans) << endl;
}
