Wrong answer error

I am not able to pass one test case. Kindly have a look at the code. I have used the 0 - 1 knapsack problem concept.

please share your code here.

So your approach can be as follows:
you can convert this problem to 0-1 knapsack.
for eg. W = 6, weights = {1,2,3,4,5,6}
values = {-1,10,15,16,20,45}
remove -1 entries as they are unavailable.
weights = { 2,3,4,5,6}
replicate those weights that can be added …eg. as W=6, wi=2 can be added 3 times.
so weights = {2,2,2,3,3,4,5,6}
values = {10,10,10,15,15,16,20,45}
now solve this as 0-1 knapsack. remember this time you need to minimize values and the weight you need is exactly W.

Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.