#include <bits/stdc++.h>
using namespace std;
set<pair<long long, long long> > s;
set<pair<long long, long long> > temp, temp2;
set<pair<long long, long long> >::iterator it1, it2;
int main() {
  long long N, K;
  scanf("%lld%lld", &N, &K);
  long long i, j;
  long long arr[N + 5];
  long long prefix[N + 5];
  prefix[0] = 0;
  for (i = 1; i <= N; i++) {
    scanf("%lld", &arr[i]);
    prefix[i] = prefix[i - 1] + arr[i];
    s.insert(make_pair(arr[i], i));
  }
  long long ans = -1e18;
  for (i = 1; i <= N; i++) {
    temp = s;
    temp2.clear();
    long long sum = 0;
    long long k;
    for (j = i; j <= N; j++) {
      temp2.insert(make_pair(arr[j], j));
      temp.erase(make_pair(arr[j], j));
      sum = prefix[j] - prefix[i - 1];
      ans = max(ans, sum);
      it2 = temp2.begin();
      k = 0;
      if (temp.size() > 0) {
        it1 = temp.end();
        it1--;
        while (k < min(j - i + 1, K) && k < min(temp.size(), temp2.size())) {
          sum -= (*it2).first;
          sum += (*it1).first;
          it2++;
          it1--;
          k++;
          ans = max(ans, sum);
        }
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
