#include <bits/stdc++.h>
using namespace std;
const int N = 201;
int n, a[N], cum[N][N], k, freq[N];
vector<int> hs;
int calc(int l, int r) {
  priority_queue<int> qu;
  int res = 0;
  for (int i = l; i <= r; ++i) {
    qu.push(-hs[a[i]]);
    res += hs[a[i]];
  }
  int sz = hs.size(), op = k;
  bool E = false;
  for (int i = sz - 1; i >= 0 && !E; --i) {
    int can = min(freq[i] - (cum[r + 1][i] - cum[l][i]), op);
    while (!qu.empty() && can > 0) {
      int v = -qu.top();
      qu.pop();
      if (v > hs[i]) {
        E = true;
        break;
      }
      res -= v;
      res += hs[i];
      --op;
      --can;
    }
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    hs.push_back(a[i]);
  }
  sort(hs.begin(), hs.end());
  hs.resize(unique(hs.begin(), hs.end()) - hs.begin());
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(hs.begin(), hs.end(), a[i]) - hs.begin();
    for (size_t j = 0; j < hs.size(); ++j) cum[i + 1][j] = cum[i][j];
    ++cum[i + 1][a[i]];
    ++freq[a[i]];
  }
  int best = -2e9;
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j) best = max(best, calc(i, j));
  printf("%d\n", best);
  return 0;
}
