Pls check the code


It passes the given test case but gives WA on submission

@Garvit012, as mentioned in the question, If price of i^th packet is -1 then this packet is not available for sale , you are not handling this case

pls check the condition in Line 14 :
if(w < n or a[n-1]==-1)

@Garvit012, yeah my bad ,
actually your input format is wrong
the first line take n and w
second line take w space seperated integer not n
i.e you have to make an array of size w not n refer below corrected code for better understanding

corrected code :-

1 Like

ohh thankyou so much but then what’s n doing?

its useless …

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.