#include <bits/stdc++.h>
using namespace std;
const int inf = -1e9;
int find_max(multiset<int> &in_range, multiset<int> &out_of_range,
             int sum_in_range) {
  while (!in_range.empty() and !out_of_range.empty() and
         *in_range.begin() < *out_of_range.rbegin()) {
    sum_in_range -= *in_range.begin();
    sum_in_range += *out_of_range.rbegin();
    in_range.erase(in_range.begin());
    out_of_range.erase(--out_of_range.end());
  }
  return sum_in_range;
}
void solve() {
  int n, k, res = inf;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int l = 0; l < n; l++) {
    for (int r = l; r < n; r++) {
      multiset<int> in_range;
      multiset<int> out_of_range;
      int sum_in_range = 0;
      for (int cur_idx = 0; cur_idx < n; cur_idx++) {
        if (cur_idx >= l and cur_idx <= r) {
          in_range.insert(v[cur_idx]);
          sum_in_range += v[cur_idx];
          if (in_range.size() > k) {
            in_range.erase(--in_range.end());
          }
        } else {
          out_of_range.insert(v[cur_idx]);
          if (out_of_range.size() > k) {
            out_of_range.erase(out_of_range.begin());
          }
        }
      }
      res = max(res, find_max(in_range, out_of_range, sum_in_range));
    }
  }
  cout << res << '\n';
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  solve();
}
