#include <bits/stdc++.h>
using namespace std;
class point {
 public:
  int x, ind;
  point(int dx = 0, int _ind = 0) {
    x = dx;
    ind = _ind;
  }
};
int n, k, f[210][210];
point a[210], c[210];
bool cmpx(point A, point B) { return A.x < B.x; }
bool cmpi(point A, point B) { return A.ind < B.ind; }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].x;
    a[i].ind = i;
    c[i] = a[i];
  }
  sort(c, c + n, cmpx);
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j)
      for (int q = i; q <= j; ++q) f[i][j] += a[q].x;
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j) {
      sort(a + i, a + j + 1, cmpx);
      int t = n - 1;
      int cnt = k;
      for (int q = i; q <= j; ++q) {
        while ((c[t].ind >= i) && (c[t].ind <= j) && (t >= 0)) --t;
        if ((t >= 0) && (cnt > 0) && (c[t].x > a[q].x)) {
          f[i][j] = f[i][j] - a[q].x + c[t].x;
          --t;
          --cnt;
        } else
          break;
      }
      sort(a + i, a + j + 1, cmpi);
    }
  int mx = f[0][0];
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j)
      if (mx < f[i][j]) mx = f[i][j];
  cout << mx;
  return 0;
}
