#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = max((ll)0, accumulate(a.begin(), a.end(), (ll)0));
  {
    ll left_ans = 0;
    for (ll i = 0; i < N - K; i++) {
      if (a[i] > 0) {
        left_ans += a[i];
      }
    }
    ll black_num = 0;
    ll whilte_num = 0;
    bool black_contiguous = true;
    bool white_contiguous = true;
    for (ll i = N - K - 1; i >= 0; i--) {
      if (a[i] == 0) {
        black_num++;
        whilte_num++;
      } else if (a[i] > 0) {
        if (black_contiguous) {
          black_num++;
        }
        white_contiguous = false;
      } else {
        if (white_contiguous) {
          whilte_num++;
        }
        black_contiguous = false;
      }
      if (!black_contiguous && !white_contiguous) {
        break;
      }
    }
    ll last = accumulate(a.begin() + N - K, a.end(), (ll)0);
    ll tmp = last;
    for (ll i = 0; i < black_num; i++) {
      tmp -= a[N - 1 - i];
      last = max(last, tmp);
    }
    ll w = 0;
    for (ll i = 0; i < whilte_num; i++) {
      if (a[N - 1 - i] > 0) {
        w += a[N - 1 - i];
      }
    }
    last = max(last, w);
    left_ans += last;
    ans = max(ans, left_ans);
  }
  {
    ll right_ans = 0;
    for (ll i = N - 1; i >= K; i--) {
      if (a[i] > 0) {
        right_ans += a[i];
      }
    }
    ll black_num = 0;
    ll whilte_num = 0;
    bool black_contiguous = true;
    bool white_contiguous = true;
    for (ll i = K; i < N; i++) {
      if (a[i] == 0) {
        black_num++;
        whilte_num++;
      } else if (a[i] > 0) {
        if (black_contiguous) {
          black_num++;
        }
        white_contiguous = false;
      } else {
        if (white_contiguous) {
          whilte_num++;
        }
        black_contiguous = false;
      }
      if (!black_contiguous && !white_contiguous) {
        break;
      }
    }
    ll last = accumulate(a.begin(), a.begin() + K, (ll)0);
    ll tmp = last;
    for (ll i = 0; i < black_num; i++) {
      tmp -= a[i];
      last = max(last, tmp);
    }
    ll w = 0;
    for (ll i = 0; i < whilte_num; i++) {
      if (a[i] > 0) {
        w += a[i];
      }
    }
    last = max(last, w);
    right_ans += last;
    ans = max(ans, right_ans);
  }
  cout << ans << endl;
}
