#include <bits/stdc++.h>
using namespace std;
const int N = 201, M = 2001;
int n, k, a[N], ans = -1 * 1000 * 1000 * 100;
int all[M], in[M];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i] += 1000;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      memset(all, 0, sizeof all);
      memset(in, 0, sizeof in);
      int sum = 0;
      for (int tmp = 1; tmp <= n; tmp++) {
        if (tmp >= i && tmp <= j)
          in[a[tmp]]++, sum += a[tmp];
        else
          all[a[tmp]]++;
      }
      int r = 2000, l = 0, kp = k;
      while (r > l && kp > 0) {
        while (all[r] == 0 && r > l) r--;
        while (in[l] == 0 && l < r) l++;
        if (r > l) kp--, in[l]--, all[r]--, in[r]++, all[l]++, sum += r - l;
      }
      ans = max(ans, sum - (j - i + 1) * 1000);
    }
  }
  cout << ans;
  return 0;
}
