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

MAX = 0
for k in range(1, K+1):
    for ka in range(k+1):
        for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:]))

print(MAX) 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 = 0 MAX 0 for k in range(1, K+1):
    for ka in range(k+1):
        for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:])) k range(1, K+1) range 1 K+1 K 1 for ka in range(k+1):
        for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:])) ka range(k+1) range k+1 k 1 for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:])) kb range(k+1-ka) range k+1-ka k+1 k 1 ka kcd = k - ka - kb kcd k - ka - kb k - ka k ka kb if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
             (ka+kb <= kcd) or (ka+kb > N) ka+kb <= kcd ka+kb ka kb kcd ka+kb > N ka+kb ka kb N continue s = V[:ka] + V[-kb:] if kb != 0 else V[:ka] s V[:ka] + V[-kb:] if kb != 0 else V[:ka] kb != 0 kb 0 V[:ka] + V[-kb:] V[:ka] V :ka ka V[-kb:] V -kb: -kb kb V[:ka] V :ka ka s.sort() s.sort s sort MAX = max(MAX, sum(s[kcd:])) MAX max(MAX, sum(s[kcd:])) max MAX sum(s[kcd:]) sum s[kcd:] s kcd: kcd print(MAX) print MAX V = list(map(int, input().split())) list(map(int, input().split())) V MAX = 0 0 MAX MAX = max(MAX, sum(s[kcd:])) max(MAX, sum(s[kcd:])) MAX K = map(int, input().split()) map(int, input().split()) K N, K = map(int, input().split()) map(int, input().split()) N kcd = k - ka - kb k - ka - kb kcd s = V[:ka] + V[-kb:] if kb != 0 else V[:ka] V[:ka] + V[-kb:] if kb != 0 else V[:ka] s

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

MAX = 0
for k in range(1, K+1):
    for ka in range(k+1):
        for kb in range(k+1-ka):
            kcd = k - ka - kb
            
            if (ka+kb <= kcd) or (ka+kb > N):
                continue
            
            #print(ka, kb, kcd)
            s = V[:ka] + V[-kb:] if kb != 0 else V[:ka]
            s.sort()
            #print(s[kcd:], sum(s[kcd:]))
            MAX = max(MAX, sum(s[kcd:]))

print(MAX)