SPOJ PARTY PROBLEM

Question — https://www.spoj.com/problems/PARTY/
My Solution — 5e2C5G - Online C++0x Compiler & Debugging Tool - Ideone.com

In my viewpoint, calculating the maximum value for party enjoyment is easy by using classical knapsack problem but when it comes to calculate the cost, not only its giving WA for cost but also it gives WA for maximum value for party enjoyment!

I used top down approach and please help me!

for cost just do this-

int max=dp[n][wt],cost=0;
for(i=0;i<=wt;i++)
if(dp[n][i]==max) {cost=i; break;}