Minimum Money Needed

I have done this using recursion so it gives TLE for first case but for second and third testcase it gives wrong answer. May I know what are those testcases? Later I will optimize it using DP. Here is the code:

@YashJ
try the test case
5 6
175 155 181 179 41 204
the correct answer is 204 you are getting 216

but then n=6 and then my code gives correct answer

ok i got it that there are W elements in array but whats the use of N?

@YashJ
n is useless .

still getting wrong answer with 33 score pls check my code - https://ide.codingblocks.com/s/316969

try for this input
5 10
-1 33 -1 176 -1 46 -1 120 -1 300
correct output : 112