Minimum money needed

error in my code ?

If you read the problem statement carefully then you will realise that the N value given in input does not represent the size of the array. Infact it is quite useless.
This is a 1D DP problem. The size of the array is W only , not N.
for test case:
5 6
175 155 181 179 41 204
the correct answer is 204
take number of input equal to W

@aa1

can u please modify the code…
i m not getting how to handle -1 case.

also having confusion…
also editorial shows in java and that too 2d dp

please can u tell 1d dp soln