KANAPSACK PROBLEM

I’m getting run time error but it runs fine in my local compiler…can someone please help with the test cases where my code fails…

my code