CSES - Shared codeLink to this code: `https://cses.fi/paste/2f6f0fdf60a71e537a397d/`
```#include<bits/stdc++.h>
using namespace std;
#define ll int
#define mp make_pair
#define p pair
#define vl vector<int>
#define fr(i,a,b) for((i)=(a);(i)<=(b);(i)++)
#define rep(j,b) for((j)=0;(j)<(b);(j)++)
#define F first
#define S second
#define pb push_back
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define all(v) (v).begin(), (v).end()
#define Sort(v) sort(all(v))
#define mod 1000000007
#define M LLONG_MAX
#define nl cout<<endl;
//ll dp[1e5 +1];

vl input_vec(int n) { ll i,a; vl vec; rep(i,n) { cin>>a; vec.pb(a); } return vec; }

void solve()
{
ll plus=0, minus=0, minn,maxx,left=0, right=1,a,b,z,ans=0;
ll n,c,q,h,k, m,i=0,j=2,w,index=0,x=0,y,d,sum=0,mid,cnt=0,temp;
cin>>n>>x;
vl price =input_vec(n);
vl pages =input_vec(n);
vector<vector<ll>> dp(n, vl(x+1,0));
rep(i,n)
{
fr(sum,0,x)
{
if(i==0)
{
if(sum>=price[i]) dp[i][sum]=max(dp[i][sum], pages[i]);
}
else
{ dp[i][sum] = dp[i-1][sum];
if(sum>=price[i]) dp[i][sum] = max(dp[i][sum], dp[i-1][sum-price[i]]+pages[i]);
}
}
}
cout<<dp[n-1][x]<<endl;

}

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(NULL);
int t=1; //cin>>t;
while(t--)
solve();
return 0;
}```