#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
long long n, k;
long long arr[314159];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  long long ans = 0;
  vector<long long> a, b;
  long long t = min(n - k, k);
  for (long long i = 1; i <= t; i++) {
    a.push_back(arr[i]);
  }
  for (long long i = t + 1; i <= n - t; i++) {
    ans += max(0LL, arr[i]);
  }
  for (long long i = n - t + 1; i <= n; i++) {
    b.push_back(arr[i]);
  }
  long long op1 = ans, op2 = ans;
  for (auto i : a) {
    op2 += max(0LL, i);
  }
  for (auto i : b) {
    op1 += max(i, 0LL);
  }
  ans = max({op1, op2, ans, 0LL});
  for (auto i : a) {
    op1 += i;
  }
  for (auto i : b) {
    op2 += i;
  }
  ans = max({ans, op1, op2, 0LL});
  cout << ans;
  return 0;
}
