import heapq
import copy
N,K = map(int, input().split())
V_list= list(map(int, input().split()))

selected = []
left = []

max_sum = 0
left_sum = 0
for l in range(N):
    selected = copy.deepcopy(left)
    lr_sum = left_sum
    for r in range(N-l+1):
        # skip
        stock = K-l-r
        if stock < 0:
            break
        ri = N-r-1
        select_cnt = len(selected)
        tmp_sum = lr_sum
        max_sum = max(max_sum, tmp_sum)
        popper = copy.deepcopy(selected)

        for i in range(stock):
            if i >= select_cnt:
                break
            
            pop_v = heapq.heappop(popper)
            if pop_v > 0:
                break
            tmp_sum -= pop_v
            max_sum = max(max_sum, tmp_sum)

        r_val = V_list[ri]
        lr_sum += r_val
        heapq.heappush(selected, r_val)

    l_val = V_list[l]
    left_sum += l_val
    heapq.heappush(left, l_val)

print(max_sum) import heapq heapq import copy copy N,K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V_list= list(map(int, input().split())) V_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split selected = [] selected [] left = [] left [] max_sum = 0 max_sum 0 left_sum = 0 left_sum 0 for l in range(N):
    selected = copy.deepcopy(left)
    lr_sum = left_sum
    for r in range(N-l+1):
        # skip
        stock = K-l-r
        if stock < 0:
            break
        ri = N-r-1
        select_cnt = len(selected)
        tmp_sum = lr_sum
        max_sum = max(max_sum, tmp_sum)
        popper = copy.deepcopy(selected)

        for i in range(stock):
            if i >= select_cnt:
                break
            
            pop_v = heapq.heappop(popper)
            if pop_v > 0:
                break
            tmp_sum -= pop_v
            max_sum = max(max_sum, tmp_sum)

        r_val = V_list[ri]
        lr_sum += r_val
        heapq.heappush(selected, r_val)

    l_val = V_list[l]
    left_sum += l_val
    heapq.heappush(left, l_val) l range(N) range N selected = copy.deepcopy(left) selected copy.deepcopy(left) copy.deepcopy copy deepcopy left lr_sum = left_sum lr_sum left_sum for r in range(N-l+1):
        # skip
        stock = K-l-r
        if stock < 0:
            break
        ri = N-r-1
        select_cnt = len(selected)
        tmp_sum = lr_sum
        max_sum = max(max_sum, tmp_sum)
        popper = copy.deepcopy(selected)

        for i in range(stock):
            if i >= select_cnt:
                break
            
            pop_v = heapq.heappop(popper)
            if pop_v > 0:
                break
            tmp_sum -= pop_v
            max_sum = max(max_sum, tmp_sum)

        r_val = V_list[ri]
        lr_sum += r_val
        heapq.heappush(selected, r_val)

     r range(N-l+1) range N-l+1 N-l N l 1 stock = K-l-r stock K-l-r K-l K l r if stock < 0:
            break
         stock < 0 stock 0 break ri = N-r-1 ri N-r-1 N-r N r 1 select_cnt = len(selected) select_cnt len(selected) len selected tmp_sum = lr_sum tmp_sum lr_sum max_sum = max(max_sum, tmp_sum) max_sum max(max_sum, tmp_sum) max max_sum tmp_sum popper = copy.deepcopy(selected) popper copy.deepcopy(selected) copy.deepcopy copy deepcopy selected for i in range(stock):
            if i >= select_cnt:
                break
            
            pop_v = heapq.heappop(popper)
            if pop_v > 0:
                break
            tmp_sum -= pop_v
            max_sum = max(max_sum, tmp_sum)

         i range(stock) range stock if i >= select_cnt:
                break
            
             i >= select_cnt i select_cnt break pop_v = heapq.heappop(popper) pop_v heapq.heappop(popper) heapq.heappop heapq heappop popper if pop_v > 0:
                break
             pop_v > 0 pop_v 0 break tmp_sum -= pop_v tmp_sum pop_v max_sum = max(max_sum, tmp_sum) max_sum max(max_sum, tmp_sum) max max_sum tmp_sum r_val = V_list[ri] r_val V_list[ri] V_list ri lr_sum += r_val lr_sum r_val heapq.heappush(selected, r_val) heapq.heappush heapq heappush selected r_val l_val = V_list[l] l_val V_list[l] V_list l left_sum += l_val left_sum l_val heapq.heappush(left, l_val) heapq.heappush heapq heappush left l_val print(max_sum) print max_sum ri = N-r-1 N-r-1 ri pop_v = heapq.heappop(popper) heapq.heappop(popper) pop_v stock = K-l-r K-l-r stock tmp_sum = lr_sum lr_sum tmp_sum popper = copy.deepcopy(selected) copy.deepcopy(selected) popper tmp_sum -= pop_v pop_v tmp_sum lr_sum += r_val r_val lr_sum selected = copy.deepcopy(left) copy.deepcopy(left) selected max_sum = max(max_sum, tmp_sum) max(max_sum, tmp_sum) max_sum N,K = map(int, input().split()) map(int, input().split()) N max_sum = 0 0 max_sum V_list= list(map(int, input().split())) list(map(int, input().split())) V_list select_cnt = len(selected) len(selected) select_cnt r_val = V_list[ri] V_list[ri] r_val left_sum += l_val l_val left_sum max_sum = max(max_sum, tmp_sum) max(max_sum, tmp_sum) max_sum selected = [] [] selected left = [] [] left lr_sum = left_sum left_sum lr_sum K = map(int, input().split()) map(int, input().split()) K left_sum = 0 0 left_sum l_val = V_list[l] V_list[l] l_val
import heapq
import copy
N,K = map(int, input().split())
V_list= list(map(int, input().split()))

selected = []
left = []

max_sum = 0
left_sum = 0
for l in range(N):
    selected = copy.deepcopy(left)
    lr_sum = left_sum
    for r in range(N-l+1):
        # skip
        stock = K-l-r
        if stock < 0:
            break
        ri = N-r-1
        select_cnt = len(selected)
        tmp_sum = lr_sum
        max_sum = max(max_sum, tmp_sum)
        popper = copy.deepcopy(selected)

        for i in range(stock):
            if i >= select_cnt:
                break
            
            pop_v = heapq.heappop(popper)
            if pop_v > 0:
                break
            tmp_sum -= pop_v
            max_sum = max(max_sum, tmp_sum)

        r_val = V_list[ri]
        lr_sum += r_val
        heapq.heappush(selected, r_val)

    l_val = V_list[l]
    left_sum += l_val
    heapq.heappush(left, l_val)

print(max_sum)