Polo the Penguin and the Test (getting WA) please help :(

I’m getting wrong answer for my submission…please check out where it is wrong
here it is CodeChef: Practical coding for everyone

Try this :

1

3 2

1 1 3

2 2 5

3 3 3

Answer should be 0 :slight_smile:

it is 0
my code is giving 0 for the above inputs you gave.

what to do now ? :frowning:

The one whose link you have given here doesn’t give 0 as the output… The problem being in the insertion sort function.

for(j=i-1;j<=0,k>tp[j];j–) should be replaced by for(j=i-1;j>=0 && k>tp[j];j–)

Your code, however, will still not give correct answers for test cases like N = 3, W = 5; {C[i], P[i], T[i]} = {(1,5,5),(1,4,3),(1,4,2)}.

Your answer will be 5. But output should be 8. :slight_smile:

Try searching for the “knapsack problem” on the web, if you still find it difficult to rectify the mistake :slight_smile: