#include <bits/stdc++.h>
using namespace std;
long long min(long long x, long long y) { return (x < y) ? x : y; }
long long max(long long x, long long y) { return (x > y) ? x : y; }
const int N = 100009;
const int M = 2000;
long long x, y, n, m, e, i, u, w, mx, z, l, r, best, cnt, g, j, k, ans;
long long a[N], b[N];
string s;
vector<long long> v;
long long solve(int l, int r) {
  int c[N];
  long long cntt = 0;
  vector<long long> v2;
  v2.empty();
  long long t, sum = 0;
  for (int i = 0; i < n; i++) c[a[i] + M] = 0;
  for (int i = l; i <= r; i++) {
    sum += a[i];
    c[a[i] + M]++;
    v2.push_back(a[i]);
  }
  sort(v2.begin(), v2.end());
  t = k;
  t = min(t, r - l + 1);
  t = min(t, n - r + l - 1);
  for (long long i = v.size() - 1; i >= 0; i--) {
    long long presum = sum;
    long long u = b[v[i] + M] - c[v[i] + M];
    u = min(t, u);
    sum += u * v[i];
    t -= u;
    for (int w = 0; w < u; w++) {
      sum = sum - v2[cntt];
      cntt++;
    }
    if (presum > sum) return presum;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  mx = -(1 << 29);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!b[a[i] + M]) v.push_back(a[i]);
    b[a[i] + M]++;
  }
  sort(v.begin(), v.end());
  cout << endl;
  for (int e = 0; e < n; e++)
    for (int j = e; j < n; j++) {
      mx = max(mx, solve(e, j));
    }
  cout << mx;
  cout << endl;
  return 0;
}
