Minimum Money needed

Can you please help me with the question??

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