n,k = map(int,input().split())
v = list(map(int,input().split()))
m = 0
for i in range(n+1):
  if i > k:
    break
  s = sum(v[:i])
  h = [j for j in v[:i] if j < 0]
  h.sort()
  m = max(m,s-sum(h[:min(len(h),k-i)]))
  for j in range(1,n-i+1):
    if i+j > k:
      break
    cs = s
    cs += sum(v[-j:])
    ch = h[:]
    ch += [j for j in v[-j:] if j < 0]
    ch.sort()
    cs -= sum(ch[:min(len(ch),k-i-j)])
    m = max(m,cs)
print(m) n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k v = list(map(int,input().split())) v list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m = 0 m 0 for i in range(n+1):
  if i > k:
    break
  s = sum(v[:i])
  h = [j for j in v[:i] if j < 0]
  h.sort()
  m = max(m,s-sum(h[:min(len(h),k-i)]))
  for j in range(1,n-i+1):
    if i+j > k:
      break
    cs = s
    cs += sum(v[-j:])
    ch = h[:]
    ch += [j for j in v[-j:] if j < 0]
    ch.sort()
    cs -= sum(ch[:min(len(ch),k-i-j)])
    m = max(m,cs) i range(n+1) range n+1 n 1 if i > k:
    break
   i > k i k break s = sum(v[:i]) s sum(v[:i]) sum v[:i] v :i i j for j in v[:i] if j < 0 for j in v[:i] if j < 0 j v[:i] v :i i j < 0 j 0 if j < 0 j h = [j for j in v[:i] if j < 0] h [j for j in v[:i] if j < 0] h.sort() h.sort h sort m = max(m,s-sum(h[:min(len(h),k-i)])) m max(m,s-sum(h[:min(len(h),k-i)])) max m s-sum(h[:min(len(h),k-i)]) s sum(h[:min(len(h),k-i)]) sum h[:min(len(h),k-i)] h :min(len(h),k-i) min(len(h),k-i) min len(h) len h k-i k i for j in range(1,n-i+1):
    if i+j > k:
      break
    cs = s
    cs += sum(v[-j:])
    ch = h[:]
    ch += [j for j in v[-j:] if j < 0]
    ch.sort()
    cs -= sum(ch[:min(len(ch),k-i-j)])
    m = max(m,cs) j range(1,n-i+1) range 1 n-i+1 n-i n i 1 if i+j > k:
      break
     i+j > k i+j i j k break cs = s cs s cs += sum(v[-j:]) cs sum(v[-j:]) sum v[-j:] v -j: -j j ch = h[:] ch h[:] h : j for j in v[-j:] if j < 0 for j in v[-j:] if j < 0 j v[-j:] v -j: -j j j < 0 j 0 if j < 0 j ch += [j for j in v[-j:] if j < 0] ch [j for j in v[-j:] if j < 0] ch.sort() ch.sort ch sort cs -= sum(ch[:min(len(ch),k-i-j)]) cs sum(ch[:min(len(ch),k-i-j)]) sum ch[:min(len(ch),k-i-j)] ch :min(len(ch),k-i-j) min(len(ch),k-i-j) min len(ch) len ch k-i-j k-i k i j m = max(m,cs) m max(m,cs) max m cs print(m) print m m = max(m,s-sum(h[:min(len(h),k-i)])) max(m,s-sum(h[:min(len(h),k-i)])) m cs = s s cs k = map(int,input().split()) map(int,input().split()) k ch += [j for j in v[-j:] if j < 0] [j for j in v[-j:] if j < 0] ch m = 0 0 m cs -= sum(ch[:min(len(ch),k-i-j)]) sum(ch[:min(len(ch),k-i-j)]) cs cs += sum(v[-j:]) sum(v[-j:]) cs s = sum(v[:i]) sum(v[:i]) s v = list(map(int,input().split())) list(map(int,input().split())) v m = max(m,cs) max(m,cs) m ch = h[:] h[:] ch n,k = map(int,input().split()) map(int,input().split()) n h = [j for j in v[:i] if j < 0] [j for j in v[:i] if j < 0] h
n,k = map(int,input().split())
v = list(map(int,input().split()))
m = 0
for i in range(n+1):
  if i > k:
    break
  s = sum(v[:i])
  h = [j for j in v[:i] if j < 0]
  h.sort()
  m = max(m,s-sum(h[:min(len(h),k-i)]))
  for j in range(1,n-i+1):
    if i+j > k:
      break
    cs = s
    cs += sum(v[-j:])
    ch = h[:]
    ch += [j for j in v[-j:] if j < 0]
    ch.sort()
    cs -= sum(ch[:min(len(ch),k-i-j)])
    m = max(m,cs)
print(m)