#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; bool isKado(int a, int b, int c) { if (a == b || b == c || c == a)RT false; static int A[3]; A[0] = a, A[1] = b, A[2] = c; sort(A, A + 3); RT b != A[1]; } int dp[51][51][51]; void solve() { rep(i, 51)rep(j, 51)rep(k, 51)rep(l, 51)dp[i][j][k] = INT_MIN / 3; int N, C; cin >> N >> C; vi L(N), W(N); rep(i, N)cin >> L[i]; rep(i, N)cin >> W[i]; rep(i, N)rep(j, N)rep(k, N) { int smCost = W[i] + W[j] + W[k]; if (isKado(L[i], L[j], L[k]) && smCost <= C) { smax(dp[smCost][L[j]][L[k]], L[i] + L[j] + L[k]); } } rep(i, C + 1)rep(j, 51)rep(k, 51) { rep(l, N) { int smCost = i + W[l]; if (smCost <= C && isKado(j, k, L[l])) { smax(dp[smCost][k][L[l]], dp[i][j][k] + L[l]); } } } int ans = 0; rep(i, 51)rep(j, 51)rep(k, 51)smax(ans, dp[i][j][k]); cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }