WA in EQGIFTS Problem on IARCS. Pls help.

iarcs
knapsack

#1

I was doing this problem on iarcs. The problem is basically a variation of knapsack. Here we require to break set in two parts such that the difference between the sum of parts is minimum. I tried it using top down approach of dp but it is only getting 90 out of 100 points.Couldn’t figure out the mistake. My solution is here.

please help me out.


#2

I think that the problem was in the test cases(nothing new) and I was getting WA because of one of the tests as well.
You can check the test data for any IARCS problem here