Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: House123

Problemset: laracroft

Language: cpp

Time: 0.004 second

Submitted On: 2026-01-17 23:28:56

#include <bits/stdc++.h>
int n,w1,dp[505][2005],vl[505],weight[505],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++){
			
			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;
			cout << dp[n][w1] << ' ' << max_w;
			break;
		}
	}
	
	
}