Solution approach considers 0/1 knapsack but in the question it is mentioned that there are infinite supply of orange packets means this is unbounded knoapsack. Also there is no consideration of logic when val[i]=-1.
Hint provided is completely wrong
@pallavivarshney267,
When infinite supply is available, then the problem is analogous to coin change problem, else it is analogous to 0/1 knapsack. Both the dp’s are quite similar, so look closely, you will find, how the hint manages to allow multiple supplies.
You can assume val[i]>0.
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.