#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const int M = 4005;
int a[N], que0[20], que1[20];
int vis[M];
int dp[N][N];
priority_queue<int, vector<int>, greater<int> > sq;
priority_queue<int, vector<int>, less<int> > bq;
int main() {
  int n, k, ans;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if (i == j)
        dp[i][j] = a[i];
      else
        dp[i][j] = dp[i][j - 1] + a[j];
    }
  ans = dp[1][n];
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    while (!bq.empty()) bq.pop();
    while (!sq.empty()) sq.pop();
    for (int j = 1; j <= n; j++) bq.push(a[j]);
    for (int j = i; j <= n; j++) {
      sq.push(a[j]);
      vis[a[j] + 1005]++;
      int index = 0;
      while (index < k && !sq.empty() && !bq.empty()) {
        int tmp = bq.top();
        if (vis[tmp + 1005] > 0) {
          vis[tmp + 1005]--;
          bq.pop();
          continue;
        }
        que0[index] = sq.top();
        sq.pop();
        que1[index] = bq.top();
        bq.pop();
        index++;
      }
      int diff = 0;
      for (int l = 0; l < index; l++) {
        if (que1[l] > que0[l])
          diff += que1[l] - que0[l];
        else
          break;
      }
      if (ans < dp[i][j] + diff) ans = dp[i][j] + diff;
      for (int l = 0; l < index; l++) {
        sq.push(que0[l]);
        bq.push(que1[l]);
      }
    }
  }
  cout << ans << endl;
}
