N, K = map(int, input().split())
V = list(map(int, input().split()))
Ans = -float('inf')
for a in range(K+1):
    for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans)
print(Ans)


 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 Ans = -float('inf') Ans -float('inf') float('inf') float 'inf' for a in range(K+1):
    for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans) a range(K+1) range K+1 K 1 for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans) b range(K+1) range K+1 K 1 if a + b > min(K, N):
            break
         a + b > min(K, N) a + b a b min(K, N) min K N break c = K - a - b c K - a - b K - a K a b A = V[:a] + V[N - b:] A V[:a] + V[N - b:] V[:a] V :a a V[N - b:] V N - b: N - b N b A.sort() A.sort A sort ans = sum(A) ans sum(A) sum A for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
         x A if c == 0:
                break
             c == 0 c 0 break if x >= 0:
                break
             x >= 0 x 0 break if x < 0:
                c -= 1
                ans -= x
         x < 0 x 0 c -= 1 c 1 ans -= x ans x Ans = max(ans, Ans) Ans max(ans, Ans) max ans Ans print(Ans) print Ans V = list(map(int, input().split())) list(map(int, input().split())) V ans = sum(A) sum(A) ans c -= 1 1 c A = V[:a] + V[N - b:] V[:a] + V[N - b:] A c = K - a - b K - a - b c Ans = max(ans, Ans) max(ans, Ans) Ans N, K = map(int, input().split()) map(int, input().split()) N K = map(int, input().split()) map(int, input().split()) K Ans = -float('inf') -float('inf') Ans ans -= x x ans
N, K = map(int, input().split())
V = list(map(int, input().split()))
Ans = -float('inf')
for a in range(K+1):
    for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans)
print(Ans)



