Need help with DP problem

I tried to solve this problem with unbounded knapsack but failing on some of the test cases.
Please help.
Problem link
Solution I tried

Comments (0)