#include <bits/stdc++.h>
using namespace std;
int a[202];
multiset<int> S1, S2;
int n, k, sol;
int sum[202];
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> k;
  sol = -10002;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sol = max(sol, a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int st = 1; st <= n; ++st) {
    S1.clear();
    S2.clear();
    for (int j = 1; j <= n; ++j) S2.insert(a[j]);
    for (int dr = st; dr <= n; ++dr) {
      S1.insert(a[dr]);
      S2.erase(S2.find(a[dr]));
      int s = sum[dr] - sum[st - 1];
      set<int>::iterator it1 = S1.begin();
      set<int>::reverse_iterator it2 = S2.rbegin();
      for (int op = 1; op <= k && it1 != S1.end() && it2 != S2.rend();
           ++op, ++it1, ++it2) {
        int x = *it1;
        int y = *it2;
        if (x < y) s += y - x;
      }
      sol = max(sol, s);
    }
  }
  cout << sol << "\n";
  return 0;
}
