Problem Statement
Book Shop
Implementation
void solve()
{
ll n, x;
cin >> n >> x;
vll cost(n), p(n);
rep(i, n) cin >> cost[i];
rep(i, n) cin >> p[i];
vll A(x + 1, 0LL), B(x + 1, 0LL);
rep(i, n)
{
rep(j, x + 1)
{
A[j] = B[j];
if (j - cost[i] >= 0)
A[j] = max(A[j], B[j - cost[i]] + p[i]);
}
rep(j, x + 1) B[j] = A[j], A[j] = 0;
}
ll ans = 0LL;
rep(i, x + 1) ans = max(ans, B[i]);
cout << ans << "\n";
}