#include #include #include using namespace std; using P = pair; int main(){ int n, c; cin >> n >> c; vector l(n); for(auto &it: l) cin >> it; vector w(n); for(auto &it: w) cin >> it; vector>> dp(c+10, vector>(60, vector

(60, {-(1 << 30), -1}))); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(l[i] == l[j] || c < w[i]+w[j]) continue; dp[w[i]+w[j]][l[i]][l[j]] = max(dp[w[i]+w[j]][l[i]][l[j]] ,{l[i]+l[j], 2}); } } for(int i = 0; i <= c; i++){ for(int j = 0; j < 60; j++){ for(int k = 0; k < 60; k++){ if(dp[i][j][k].first < 0) continue; for(int ii = 0; ii < n; ii++){ if(j != k && j != l[ii] && k != l[ii] && i+w[ii] <= c && (max({j, k, l[ii]}) == k || min({j, k, l[ii]}) == k)){ dp[i+w[ii]][k][l[ii]] = max(dp[i+w[ii]][k][l[ii]], {dp[i][j][k].first+l[ii], dp[i][j][k].second+1}); } } } } } int ans = 0; for(int i = 0; i <= c; i++){ for(int j = 0; j < 60; j++){ for(int k = 0; k < 60; k++){ if(3 <= dp[i][j][k].second) ans = max(ans, dp[i][j][k].first); } } } cout << ans << endl; return 0; }