#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 6;
const long long MOD = 1e9 + 7;
const long long LLINF = 1LL << 60;
int main() {
  int N, K;
  cin >> N >> K;
  long long a[N];
  for (int i = 0; i < (int)(N); i++) cin >> a[i];
  long long ansL = 0, ansR = 0;
  long long sum[N + 1];
  sum[0] = 0;
  for (int i = 0; i < (int)(N); i++) sum[i + 1] = sum[i] + a[i];
  for (int i = 0; i < N - K; ++i) {
    if (a[i] > 0) ansL += a[i];
  }
  ansL = max(ansL, ansL + sum[N] - sum[N - K]);
  for (int i = N - 1; i >= N - K; --i) {
    if (a[i] > 0) ansR += a[i];
  }
  ansR = max(ansR, ansR + sum[N - K]);
  long long ansLR = 0;
  for (int i = 0; i < (N - K) / 2; ++i) {
    if (a[i] > 0) ansLR += a[i];
    if (a[N - 1 - i] > 0) ansLR += a[N - 1 - i];
  }
  cout << max(max(ansL, ansR), ansLR) << endl;
}
