#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; int dp[51][51][51][51]; void amax(int &res, int &a, const int &b) { a = max(a, b); res = max(res, b); } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, C; cin >> N >> C; vector > A(N); for (int i = 0; i < N; i++) { cin >> A[i].first; } for (int i = 0; i < N; i++) { cin >> A[i].second; } sort(A.begin(), A.end()); for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (A[j].first != A[k].first && A[j].second + A[k].second <= C) { dp[2][j][k][A[j].second + A[k].second] = A[j].first + A[k].first; } } } int res = 0; for (int i = 2; i < C; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (A[j].first != A[k].first) { for (int x = 0; x < N; x++) { if ((j - k) * (k - x) < 0 && A[j].first != A[x].first && A[k].first != A[x].first) { for (int w = 0; w + A[x].second <= C; w++) { if (dp[i][j][k][w] != 0) { amax(res, dp[i + 1][k][x][w + A[x].second], dp[i][j][k][w] + A[x].first); } } } } } } } } /*cerr << dp[2][1][3][6] << endl; cerr << dp[3][3][0][9] << endl; cerr << dp[4][0][1][10] << endl;*/ cout << res << endl; }