Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: mantaggez
Problemset: laracroft
Language: cpp
Time: 0.004 second
Submitted On: 2026-03-11 15:22:17
#include <bits/stdc++.h>
using namespace std;
const int nx = 5e2+5;
const int wx = 2e3+5;
int N, W, g[nx], w[nx], dp[nx][wx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin >> N >> W;
for(int i=1;i<=N;i++) cin >> g[i];
for(int i=1;i<=N;i++) cin >> w[i];
for(int i=1;i<=N;i++)
{
for(int j=1;j<=W;j++)
{
if(w[i] <= j)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + g[i]);
else
dp[i][j] = dp[i - 1][j];
// cout << dp[i][j] << ' ';
}
// cout << '\n';
}
pair<int, int> res;
for(int i=1;i<=W;i++)
if(dp[N][i] > res.first) res = {dp[N][i], i};
cout << res.first << ' ' << res.second ;
return 0;
}