CSES - Shared codeLink to this code: https://cses.fi/paste/09f6c64e9dbfd39f1aed9d/
#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PB push_back
#define RS resize
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define ITR(i, n) for(int i = 0; i < n; i++)
#define M 1000000007

typedef int_fast32_t fint;
typedef int_fast64_t fint64;
typedef vector<fint> vi;
typedef vector<vector<fint>> vvi;
typedef pair<fint, fint> pi;
typedef vector<pair<fint, fint>> vpi;
typedef map<fint, fint> imap;
typedef long long ll;


void solve() {
	fint n, x;
	cin >> n >> x;
	
	vpi books(n+1);
	fint smol = INT_MAX;
	REP(i, 1, n) {
		cin >> books[i].F;
		if(smol > books[i].F) smol = books[i].F;
	}
	REP(i, 1, n) cin >> books[i].S;
	
	vvi mp(n+1, vi(x+1, 0));
	
	REP(i, 1, n)
	REP(j, smol, x)
		if(books[i].F <= j)
			mp[i][j] = max(mp[i-1][j-books[i].F] + books[i].S, mp[i-1][j]);
		else mp[i][j] = mp[i-1][j];
	
	cout << mp[n][x];
}

int main() {
	io
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	fint t = 1;
	//cin >> t;
	
	while(t--)
		solve();
	
	return 0;
}