import bisect
N, K = map(int, input().split())
V = list(map(int, input().split()))
num_get = min(N, K)
ans = -float('inf')
for left in range(0, num_get+1):
    for right in range(N-1, N-1 - (num_get+1 - left), -1):
        inhand = sorted(V[0:left] + V[right+1:N])
        zero_idx = bisect.bisect_left(inhand, 0)
        tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):])
        ans = max(ans, tmp_ans)
print(ans) import bisect bisect 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 num_get = min(N, K) num_get min(N, K) min N K ans = -float('inf') ans -float('inf') float('inf') float 'inf' for left in range(0, num_get+1):
    for right in range(N-1, N-1 - (num_get+1 - left), -1):
        inhand = sorted(V[0:left] + V[right+1:N])
        zero_idx = bisect.bisect_left(inhand, 0)
        tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):])
        ans = max(ans, tmp_ans) left range(0, num_get+1) range 0 num_get+1 num_get 1 for right in range(N-1, N-1 - (num_get+1 - left), -1):
        inhand = sorted(V[0:left] + V[right+1:N])
        zero_idx = bisect.bisect_left(inhand, 0)
        tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):])
        ans = max(ans, tmp_ans) right range(N-1, N-1 - (num_get+1 - left), -1) range N-1 N 1 N-1 - (num_get+1 - left) N-1 N 1 num_get+1 - left num_get+1 num_get 1 left -1 inhand = sorted(V[0:left] + V[right+1:N]) inhand sorted(V[0:left] + V[right+1:N]) sorted V[0:left] + V[right+1:N] V[0:left] V 0:left 0 left V[right+1:N] V right+1:N right+1 right 1 N zero_idx = bisect.bisect_left(inhand, 0) zero_idx bisect.bisect_left(inhand, 0) bisect.bisect_left bisect bisect_left inhand 0 tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):]) tmp_ans sum(inhand[min(zero_idx, max(K - len(inhand), 0)):]) sum inhand[min(zero_idx, max(K - len(inhand), 0)):] inhand min(zero_idx, max(K - len(inhand), 0)): min(zero_idx, max(K - len(inhand), 0)) min zero_idx max(K - len(inhand), 0) max K - len(inhand) K len(inhand) len inhand 0 ans = max(ans, tmp_ans) ans max(ans, tmp_ans) max ans tmp_ans print(ans) print ans tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):]) sum(inhand[min(zero_idx, max(K - len(inhand), 0)):]) tmp_ans V = list(map(int, input().split())) list(map(int, input().split())) V ans = -float('inf') -float('inf') ans inhand = sorted(V[0:left] + V[right+1:N]) sorted(V[0:left] + V[right+1:N]) inhand N, K = map(int, input().split()) map(int, input().split()) N zero_idx = bisect.bisect_left(inhand, 0) bisect.bisect_left(inhand, 0) zero_idx num_get = min(N, K) min(N, K) num_get ans = max(ans, tmp_ans) max(ans, tmp_ans) ans K = map(int, input().split()) map(int, input().split()) K
import bisect
N, K = map(int, input().split())
V = list(map(int, input().split()))
num_get = min(N, K)
ans = -float('inf')
for left in range(0, num_get+1):
    for right in range(N-1, N-1 - (num_get+1 - left), -1):
        inhand = sorted(V[0:left] + V[right+1:N])
        zero_idx = bisect.bisect_left(inhand, 0)
        tmp_ans = sum(inhand[min(zero_idx, max(K - len(inhand), 0)):])
        ans = max(ans, tmp_ans)
print(ans)