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

ans = -(10**9)
for A in range(0,K+1,1):
    for B in range(0,min(K,N)-A+1,1):
        tmp = V[0:A] + V[N-B:N]
        tmp.sort()
        for i in range(0,min(K-A-B,A+B),1):
            tmp[i]=max(tmp[i],0)
        ans = max(ans,sum(tmp))
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 = -(10**9) ans -(10**9) 10**9 10 9 for A in range(0,K+1,1):
    for B in range(0,min(K,N)-A+1,1):
        tmp = V[0:A] + V[N-B:N]
        tmp.sort()
        for i in range(0,min(K-A-B,A+B),1):
            tmp[i]=max(tmp[i],0)
        ans = max(ans,sum(tmp)) A range(0,K+1,1) range 0 K+1 K 1 1 for B in range(0,min(K,N)-A+1,1):
        tmp = V[0:A] + V[N-B:N]
        tmp.sort()
        for i in range(0,min(K-A-B,A+B),1):
            tmp[i]=max(tmp[i],0)
        ans = max(ans,sum(tmp)) B range(0,min(K,N)-A+1,1) range 0 min(K,N)-A+1 min(K,N)-A min(K,N) min K N A 1 1 tmp = V[0:A] + V[N-B:N] tmp V[0:A] + V[N-B:N] V[0:A] V 0:A 0 A V[N-B:N] V N-B:N N-B N B N tmp.sort() tmp.sort tmp sort for i in range(0,min(K-A-B,A+B),1):
            tmp[i]=max(tmp[i],0)
         i range(0,min(K-A-B,A+B),1) range 0 min(K-A-B,A+B) min K-A-B K-A K A B A+B A B 1 tmp[i]=max(tmp[i],0) tmp[i] tmp i max(tmp[i],0) max tmp[i] tmp i 0 ans = max(ans,sum(tmp)) ans max(ans,sum(tmp)) max ans sum(tmp) sum tmp print(ans) print ans ans = max(ans,sum(tmp)) max(ans,sum(tmp)) ans N,K=map(int,input().split()) map(int,input().split()) N K=map(int,input().split()) map(int,input().split()) K V = list(map(int,input().split())) list(map(int,input().split())) V ans = -(10**9) -(10**9) ans tmp = V[0:A] + V[N-B:N] V[0:A] + V[N-B:N] tmp
N,K=map(int,input().split())
V = list(map(int,input().split()))

ans = -(10**9)
for A in range(0,K+1,1):
    for B in range(0,min(K,N)-A+1,1):
        tmp = V[0:A] + V[N-B:N]
        tmp.sort()
        for i in range(0,min(K-A-B,A+B),1):
            tmp[i]=max(tmp[i],0)
        ans = max(ans,sum(tmp))
print(ans)