#include <bits/stdc++.h>
using namespace std;
int a, f[300], k = -1, m[300][20], n[300][20];
long long mx = -9999999;
int main() {
  for (int i = 0; i <= 250; i++) {
    for (int q = 0; q <= 15; q++) {
      m[i][q] = -2000;
      n[i][q] = -2000;
    }
  }
  scanf("%d %d", &a, &k);
  for (int i = 1; i <= a; i++) {
    scanf("%d", &f[i]);
    for (int q = k; q >= 1; q--) m[i][q] = m[i - 1][q];
    for (int q = k; q >= 1; q--) {
      if (f[i] > m[i][q]) {
        for (int w = 1; w <= q - 1; w++) m[i][w] = m[i][w + 1];
        m[i][q] = f[i];
        break;
      }
    }
  }
  for (int i = a; i >= 1; i--) {
    for (int q = k; q >= 1; q--) n[i][q] = n[i + 1][q];
    for (int q = k; q >= 1; q--) {
      if (f[i] > n[i][q]) {
        for (int w = 1; w <= q - 1; w++) n[i][w] = n[i][w + 1];
        n[i][q] = f[i];
        break;
      }
    }
  }
  int Q[500] = {0};
  for (int i = 1; i <= a; i++) {
    int V[20], SS = 0, LL = 0;
    for (int q = 0; q <= k + 5; q++) V[q] = 2000;
    for (int q = i; q <= a; q++) {
      LL += f[q];
      SS = LL;
      for (int w = k; w >= 1; w--) {
        if (f[q] < V[w]) {
          for (int e = 1; e <= w - 1; e++) V[e] = V[e + 1];
          V[w] = f[q];
          break;
        }
      }
      int urt = 0;
      for (int w = k; w >= 1; w--) {
        if (m[i - 1][w] != -2000) {
          Q[urt] = m[i - 1][w];
          urt++;
        }
        if (n[q + 1][w] != -2000) {
          Q[urt] = n[q + 1][w];
          urt++;
        }
      }
      sort(Q, Q + urt);
      urt--;
      for (int w = k; w >= 1; w--) {
        if (urt < 0 || V[w] == 2000) break;
        if (V[w] <= Q[urt]) {
          SS = SS - V[w] + Q[urt];
          urt--;
        }
      }
      if (SS > mx) mx = SS;
      if (LL > mx) mx = SS;
    }
  }
  printf("%lld", mx);
  return 0;
}
