n,k = map(int,input().split())
v = [0]+[int(i) for i in input().split()]+[0]
ans = 0
cnt1 = 0
m1 = []
for i in range(n+1):
    cnt1 += v[i]
    if v[i] < 0: m1.append(v[i])
    cnt2 = cnt1
    m2 = m1[:]
    for j in range(n-i+1):
        if i + j > k: break
        r = k - i - j
        cnt2 += v[n+1-j]
        if v[n+1-j] < 0: m2.append(v[n+1-j])
        m2.sort()
        s = cnt2
        s -= sum(m2[:r])
        ans = max(s,ans)
print(ans) n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i v = [0]+[int(i) for i in input().split()]+[0] v [0]+[int(i) for i in input().split()]+[0] [0]+[int(i) for i in input().split()] [0] 0 [int(i) for i in input().split()] [0] 0 ans = 0 ans 0 cnt1 = 0 cnt1 0 m1 = [] m1 [] for i in range(n+1):
    cnt1 += v[i]
    if v[i] < 0: m1.append(v[i])
    cnt2 = cnt1
    m2 = m1[:]
    for j in range(n-i+1):
        if i + j > k: break
        r = k - i - j
        cnt2 += v[n+1-j]
        if v[n+1-j] < 0: m2.append(v[n+1-j])
        m2.sort()
        s = cnt2
        s -= sum(m2[:r])
        ans = max(s,ans) i range(n+1) range n+1 n 1 cnt1 += v[i] cnt1 v[i] v i if v[i] < 0: m1.append(v[i])
     v[i] < 0 v[i] v i 0 cnt2 = cnt1 cnt2 cnt1 m2 = m1[:] m2 m1[:] m1 : for j in range(n-i+1):
        if i + j > k: break
        r = k - i - j
        cnt2 += v[n+1-j]
        if v[n+1-j] < 0: m2.append(v[n+1-j])
        m2.sort()
        s = cnt2
        s -= sum(m2[:r])
        ans = max(s,ans) j range(n-i+1) range n-i+1 n-i n i 1 if i + j > k: break
         i + j > k i + j i j k r = k - i - j r k - i - j k - i k i j cnt2 += v[n+1-j] cnt2 v[n+1-j] v n+1-j n+1 n 1 j if v[n+1-j] < 0: m2.append(v[n+1-j])
         v[n+1-j] < 0 v[n+1-j] v n+1-j n+1 n 1 j 0 m2.sort() m2.sort m2 sort s = cnt2 s cnt2 s -= sum(m2[:r]) s sum(m2[:r]) sum m2[:r] m2 :r r ans = max(s,ans) ans max(s,ans) max s ans print(ans) print ans s -= sum(m2[:r]) sum(m2[:r]) s ans = max(s,ans) max(s,ans) ans ans = 0 0 ans s = cnt2 cnt2 s v = [0]+[int(i) for i in input().split()]+[0] [0]+[int(i) for i in input().split()]+[0] v cnt1 = 0 0 cnt1 k = map(int,input().split()) map(int,input().split()) k m1 = [] [] m1 m2 = m1[:] m1[:] m2 cnt2 = cnt1 cnt1 cnt2 cnt2 += v[n+1-j] v[n+1-j] cnt2 n,k = map(int,input().split()) map(int,input().split()) n cnt1 += v[i] v[i] cnt1 r = k - i - j k - i - j r
n,k = map(int,input().split())
v = [0]+[int(i) for i in input().split()]+[0]
ans = 0
cnt1 = 0
m1 = []
for i in range(n+1):
    cnt1 += v[i]
    if v[i] < 0: m1.append(v[i])
    cnt2 = cnt1
    m2 = m1[:]
    for j in range(n-i+1):
        if i + j > k: break
        r = k - i - j
        cnt2 += v[n+1-j]
        if v[n+1-j] < 0: m2.append(v[n+1-j])
        m2.sort()
        s = cnt2
        s -= sum(m2[:r])
        ans = max(s,ans)
print(ans)