#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, K;
cin >> n >> K;
vector<int> W(n), C(n);
for (int i = 0; i < n; i++) {
cin >> W[i];
}
for (int i = 0; i < n; i++) {
cin >> C[i];
}
vector<int> dp(K+1, 0);
for (int i = 0; i < n; i++) {
for (int j = K; j >= W[i]; j--) {
dp[j] = max(dp[j], dp[j-W[i]] + C[i]);
}
}
cout << dp[K] << endl;
return 0;
}