Link to this code: https://cses.fi/paste/31a10089630000cd20d9fe/
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
//#define mp make_pair
#define loop(a,b,i) for(ll i=a;i<b;i++)
#define loop1(a,b,i) for(ll i=a;i>=b;i--)
#define nn cout<<"NO"<<endl
#define yy cout<<"YES"<<endl
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
ll query(ll l, ll r)
{
    cout << "? " << l << " " << r << endl;
    cout.flush();
    ll a;
    cin >> a;
    return a;
}
ll mod = 1e9 + 7;
void solve()
{
    ll n, x;
    cin >> n >> x;
    ll p[n], pg[n];
    loop(0, n, i)cin >> p[i];
    loop(0, n, i)cin >> pg[i];
    ll dp[n + 2][x + 2];
    memset(dp, 0, sizeof(dp));
    loop(0, n, i)
    {
        dp[0][i] = 0;
        dp[i][0] = 0;
    }
    loop(1, n + 1, i)
    {
        loop(1, x + 1, j)
        {
            if (p[i - 1] > j)
            {
                dp[i][j] = dp[i - 1][j];
            }
            else
            {
                dp[i][j] = max(pg[i - 1] + dp[i - 1][j - p[i - 1]], dp[i - 1][j]);
            }

        }

    }

    cout << dp[n][x];
}


int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}