import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) # list 多重リスト生成 def dlist(*l, fill=None): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] n,c = list(map(int, input().split())) l = list(map(int, input().split())) w = list(map(int, input().split())) index = list(range(n)) index.sort(key=lambda i: w[i]) l = [l[i] for i in index] w = [w[i] for i in index] dp = {(-1,-1,0): 0} ans = 0 while dp: ndp = {} for (i,j,k),val in dp.items(): for ii in range(n): ll = l[ii] ww = w[ii] if ww+k>c: break if ll==i or ll==j: continue if i!=-1 and j!=-1: if (j-i)*(ll-j)>0: continue ans = max(ans, val+ll) nk = (j,ll,ww+k) ndp.setdefault(nk, 0) ndp[nk] = max(ndp[nk], val+ll) dp = ndp # print(dp) print(ans)