N,K = map(int,input().split()) A = list(map(int,input().split())) maxS = 0 minS = 0 for i in range(N): if A[i] > 0: maxS += A[i] else: minS += A[i] A,B = A[:N // 2],A[N // 2:] from collections import defaultdict # {おいしさ:個数}を作る def search(X): dic = defaultdict(int) n = len(X) for i in range(1 << n): val = 0 for j in range(n): if (i >> j) & 1: val += X[j] dic[val] += 1 return dic A = search(A) B = search(B) def srt(X): # ある数以上の数が何個あるかを、ある数でソートした状態で返す X = sorted(X.items(), key = lambda x:x[0]) n = len(X) X = [list(X[i]) for i in range(n)] for i in range(n - 1, 0, -1): X[i - 1][1] += X[i][1] num = [0] * n cnt = [0] * n for i in range(n): num[i], cnt[i] = X[i] return num, cnt Bnum, Bcnt = srt(B) import bisect def is_ok(x): # x以上の数をK個以上作れればOK cnt = 0 # print("x",x,"以上の値を",K,"個以上作れるか") for key, value in A.items(): # print("Aのkey",key,"が",value,"個") target = x - key # target以上の数がいくつあるか # print("Bnum",Bnum,"にkey",key,"に対してtarget",target,"以上の数がいくつあるか") ind = bisect.bisect_left(Bnum, target) # print("Bcnt",Bcnt,"ind",ind,) if len(Bnum) == ind: # 作れない # print("作れない") continue cnt += Bcnt[ind] * value if cnt >= K: # print(cnt,"個作れた") return True # print("作れない") return False ng = maxS ok = minS - 1 while ng - ok > 1: mid = (ng + ok) // 2 # print("ok",ok,"ng",ng,"mid",mid) # if mid < 0 and (ok + ng) % 2 == 1: # mid -= 1 if is_ok(mid): ok = mid else: ng = mid print(ok)