SRM 547 - Div2 - 500 - PillarsDivTwo

I am trying to solve the following problem -
using the dynamic programming approach, and I have written down the following code to solve the problem, but unfortunately it fails on a couple of test cases when I run the practice tests in the practice room, can anybody point out the flaw in my approach to solving this problem or suggest a tweak if there is any error in coding. I have commented the code at appropriate places to make the approach clear. Here is the link to the topcoder forum for the same problem -
this link will help in dp approach :slight_smile: