n,c = map(int,input().split()) l = [int(i) for i in input().split()] w = [int(i) for i in input().split()] cdd = {} for i in range(n): if l[i] in cdd: cdd[l[i]] = min(cdd[l[i]],w[i]) else: cdd[l[i]] = w[i] num = len(cdd) if num <= 2: print(0) exit() kh = [] for li in cdd: kh.append([li,cdd[li]]) #kh.sort() #print(kh) dp = [[0]*(c+1) for i in range((num)*num)] for i in range(num): dp[i][kh[i][1]] = kh[i][0] for i in range(num): for j in range(num): if i == j: continue for k in range(c+1): if dp[i][k] != 0 and k+kh[j][1] <= c: dp[i*num+j][k+kh[j][1]] = max(dp[i][k] + kh[j][0],dp[i*num+j][k+kh[j][1]]) ans = 0 for m in range(c): ndp = [[0]*(c+1) for i in range((num)*num)] for i in range(num*num): for j in range(num): a0 = i//num a1 = i%num if a0 == j or a1 == j:#同じ長さならスルー continue for k in range(m,c+1): if dp[i][k] != 0 and k+kh[j][1] <= c: if a0 < a1: if a1 > j: tmp = max(dp[i][k] + kh[j][0],ndp[a1*num+j][k+kh[j][1]]) ndp[a1*num+j][k+kh[j][1]] = tmp ans = max(tmp,ans) else: if a1 < j: tmp = max(dp[i][k] + kh[j][0],ndp[a1*num+j][k+kh[j][1]]) ndp[a1*num+j][k+kh[j][1]] = tmp ans = max(tmp,ans) #print(dp,ndp) dp = ndp[:] print(ans)