N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = -10**9
for kL in range(0, K+1):
    for kR in range(0, K+1):
        if kL + kR > min(N, K):
            continue
        vL = V[:kL]
        vR = []
        if kR:
            vR = V[-kR:]
        hand = list(sorted(vL + vR, reverse=True))
        rest = K - (kL + kR)
        for kD in range(rest):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
        value = sum(hand[:K])
        if value > max_value:
            max_value = value
print(max_value) 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 max_value = -10**9 max_value -10**9 -10 9 for kL in range(0, K+1):
    for kR in range(0, K+1):
        if kL + kR > min(N, K):
            continue
        vL = V[:kL]
        vR = []
        if kR:
            vR = V[-kR:]
        hand = list(sorted(vL + vR, reverse=True))
        rest = K - (kL + kR)
        for kD in range(rest):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
        value = sum(hand[:K])
        if value > max_value:
            max_value = value kL range(0, K+1) range 0 K+1 K 1 for kR in range(0, K+1):
        if kL + kR > min(N, K):
            continue
        vL = V[:kL]
        vR = []
        if kR:
            vR = V[-kR:]
        hand = list(sorted(vL + vR, reverse=True))
        rest = K - (kL + kR)
        for kD in range(rest):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
        value = sum(hand[:K])
        if value > max_value:
            max_value = value kR range(0, K+1) range 0 K+1 K 1 if kL + kR > min(N, K):
            continue
         kL + kR > min(N, K) kL + kR kL kR min(N, K) min N K continue vL = V[:kL] vL V[:kL] V :kL kL vR = [] vR [] if kR:
            vR = V[-kR:]
         kR vR = V[-kR:] vR V[-kR:] V -kR: -kR kR hand = list(sorted(vL + vR, reverse=True)) hand list(sorted(vL + vR, reverse=True)) list sorted(vL + vR, reverse=True) sorted vL + vR vL vR reverse=True reverse True rest = K - (kL + kR) rest K - (kL + kR) K kL + kR kL kR for kD in range(rest):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
         kD range(rest) range rest if len(hand) == 0:
                break
             len(hand) == 0 len(hand) len hand 0 break if hand[-1] < 0:
                hand.pop()
            else:
                break
         hand[-1] < 0 hand[-1] hand -1 0 hand.pop() hand.pop hand pop break value = sum(hand[:K]) value sum(hand[:K]) sum hand[:K] hand :K K if value > max_value:
            max_value = value value > max_value value max_value max_value = value max_value value print(max_value) print max_value V = list(map(int, input().split())) list(map(int, input().split())) V rest = K - (kL + kR) K - (kL + kR) rest vR = V[-kR:] V[-kR:] vR value = sum(hand[:K]) sum(hand[:K]) value N, K = map(int, input().split()) map(int, input().split()) N vL = V[:kL] V[:kL] vL vR = [] [] vR hand = list(sorted(vL + vR, reverse=True)) list(sorted(vL + vR, reverse=True)) hand max_value = value value max_value K = map(int, input().split()) map(int, input().split()) K max_value = -10**9 -10**9 max_value
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = -10**9
for kL in range(0, K+1):
    for kR in range(0, K+1):
        if kL + kR > min(N, K):
            continue
        vL = V[:kL]
        vR = []
        if kR:
            vR = V[-kR:]
        hand = list(sorted(vL + vR, reverse=True))
        rest = K - (kL + kR)
        for kD in range(rest):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
        value = sum(hand[:K])
        if value > max_value:
            max_value = value
print(max_value)
