Submission

Status:

[PPPPPPPPPPxSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: House123

Problemset: laracroft

Language: cpp

Time: 0.004 second

Submitted On: 2026-01-17 23:19:26

#include <bits/stdc++.h>
int n,w1,dp[500][2000],vl[500],weight[500],max_w = 0,max_dp = 0;
using namespace std;
int main(){
	cin >> n >> w1;
	for(int i = 0; i < n; i++) cin >> vl[i];
	for(int i = 0; i < n; i++) cin >> weight[i];
	
	for(int i = 1; i <= n;i++){
		for(int w = 0; w <= w1;w++){
			dp[0][w] = 0;
			if(weight[i-1] > w){
				dp[i][w] = dp[i-1][w];
			} else {
				dp[i][w] = max(dp[i-1][w], vl[i-1] + dp[i-1][w-weight[i-1]]);
			}
		}
	}
	
	for(int w = 0; w <= w1; w++){
		if(dp[n][w] == dp[n][w1]){
			max_w = w;
			break;
		}
	}
	cout << dp[n][w1] << ' ' << max_w;
	
}