Sir doubt in this question

whats wrong in this question?

Hey @tejasddongare
Please elaborate your question?

Cody went to the market to buy some oranges for his N friends. There he finds orange wrapped in packets, with the price of i^th packet as val[i]. Now he wants to buy exactly W kg oranges, so he wants you to tell him what minimum price he should pay to buy exactly W kg oranges. Weight of i^th packet is i kg. If price of i^th packet is -1 then this packet is not available for sale. The market has infinite supply of orange packets.

Input Format

First line of input contains two space separated integers N and W, the number of friend he has and the amount of Oranges in kilograms which he should buy.

The second line contains W space separated integers in which the i^th^ integer specifies the price of a ‘i’kg apple packet. A value of -1 denotes that the corresponding packet is unavailable

Constraints

1 <= N,W,val[ ] <= 10^3

Output Format

Output a single integer denoting the minimum price Code should pay to get exactly W kg oranges. Else print -1 if it is not possible to fill the bag.

Sample Input

5 5 1 2 3 4 5

Sample Output

5

sir this is the question

This is the question but what do u want to know ??

why is this question failing test cases?

Please share your code for that :slight_smile:

here is the code

Hey @tejasddongare
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.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.