Help Needed Genuinely, Please help me solve this question

Problematic Problem This is the Contest Link of Hackerrank which has one question in it named as Bob’s Date. Pls help me by solving this question, I wrote a DP solution but it is failing on some TestCases Can someone pls solve it.