Help Needed DP Question

Pls help me by solving this question Problematic Problem This is the Contest Link of Hackerrank which has one question in it named as Bob’s Date. First this is not an Ongoing Contest This is a Demo Contest which is made by my friend and I am not able to solve this question.I wrote a DP solution but it is failing on some TestCases Can someone pls solve it or give hints for the same.

This link leads to the contest registration and then problem will open if I gave u the link of the problem page not found will come. So to see the question you need to signup first.

Help Needed!!!

Are you sure that there exists an O(NW) solution to this as I doubt that it can be solved in less than O(NW^2). If the problem statement asks for any combination with total weight W then it can be solved in O(NW) .

I don’t know, what I did to solve this which takes O(W x N x N)