Colorful Knapsack help

I am not able to pass all the test cases, if someone can tell me what I am missing.
Here’s my code.