CSES - Shared codeLink to this code: https://cses.fi/paste/7c9e1dfef6715b96701c1e/
#include<iostream>
#include<cstring>
#define noob ios::sync_with_stdio(0);cin.tie(0);
using namespace std ;
int main(){
    noob
    int n,m;
    cin>>n>>m;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int j=0;j<n;j++)cin>>b[j];
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m;j++){
            dp[i][j]=dp[i-1][j];
            if(j>=a[i-1]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-a[i-1]]+b[i-1]);
            }
        }
    }
    cout<<dp[n][m]<<endl;
}