#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wwrite-strings"
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &A) {
  out << A.first << "_" << A.second;
  return out;
}
template <template <typename, typename> class ContainerT, typename ValueT>
ostream &operator<<(ostream &out,
                    const ContainerT<ValueT, std::allocator<ValueT> > &A) {
  for (__typeof((A).begin()) i = (A).begin(); i != (A).end(); ++i)
    out << *i << " ";
  return out;
}
template <template <typename, typename> class ContainerT, typename ValueT,
          typename ValueU>
ostream &operator<<(
    ostream &out, const ContainerT<pair<ValueT, ValueU>,
                                   std::allocator<pair<ValueT, ValueU> > > &A) {
  for (__typeof((A).begin()) i = (A).begin(); i != (A).end(); ++i)
    out << *i << " ";
  return out;
}
template <class T>
void mini(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
void maxi(T &a, const T &b) {
  if (b > a) a = b;
}
int N, K;
vector<int> A;
multiset<int> B;
long long solve() {
  cin >> N >> K;
  A = vector<int>(N);
  B.clear();
  for (int i = 0; i < (N); ++i) cin >> A[i];
  for (__typeof((A).begin()) i = (A).begin(); i != (A).end(); ++i) B.insert(*i);
  int ans = INT_MIN;
  for (int l = 0; l < (N); ++l) {
    multiset<int> mins;
    int curSum = 0;
    for (int r = (l); r <= (N - 1); ++r) {
      curSum += A[r];
      mins.insert(A[r]);
      for (int i = (l); i <= (r); ++i) B.erase(B.find(A[i]));
      int k = 0;
      int curAns = curSum;
      multiset<int>::reverse_iterator rit = B.rbegin();
      set<int>::iterator it = mins.begin();
      for (int i = 0; i < (K); ++i) {
        if (rit == B.rend()) break;
        if (it == mins.end()) break;
        if (*rit < *it) break;
        curAns += *rit - *it;
        ++rit;
        ++it;
      }
      maxi(ans, curAns);
      for (int i = (l); i <= (r); ++i) B.insert(A[i]);
      assert(B.size() == N);
    }
  }
  return ans;
}
int main() {
  cout << solve() << endl;
  return 0;
}
