#include <bits/stdc++.h>
using namespace std;
int a[205];
int dp[205][205];
int N, K;
int main() {
  int i, j, k, m, t, sum, s;
  int x1[205], x2[205], f1, f2;
  scanf("%d%d", &N, &K);
  for (i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (i = 1; i <= N; i++) {
    dp[i][i - 1] = 0;
    for (j = i; j <= N; j++) dp[i][j] = dp[i][j - 1] + a[j];
  }
  sum = -1000000;
  for (i = 1; i <= N; i++) {
    for (j = i; j <= N; j++) {
      f1 = 0;
      f2 = 0;
      for (k = 1; k <= N; k++) {
        if (k >= i && k <= j)
          x1[f1++] = a[k];
        else
          x2[f2++] = a[k];
      }
      sort(x1, x1 + f1);
      sort(x2, x2 + f2);
      k = K;
      int t1 = 0, t2 = f2 - 1;
      s = dp[i][j];
      if (s > sum) sum = s;
      while (k-- && t1 < f1 && t2 >= 0) {
        s = s - x1[t1] + x2[t2];
        t1++;
        t2--;
        if (s > sum) sum = s;
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
