The code is working fine on sampe testcase


all the test cases are showing wrong answer.
is my approach or logic is wrong???

Hi @Adi_choudhary,
There are logical errors in your code. Also it seems as if it has been blindly pasted from the web. Kindly refrain from such activities.

Also it is given that in the question that: If price of i^th packet is -1 then this packet is not available for sale.
You have not incorporated any such condition in your code. Please correct it.

i think you have to go through my code again. there is if condition to leave the unavailable item.
i added a comment to highlight the condition to remove the -1 element for array .


is this condition is not wroking enough??

Hi @Adi_choudhary,

I told you before. It looks as if you have copied the entire code as it is from GeeksForGeeks. Almost every line is same even including the variable names. And, that code won’t work. So please think yourself of an approach.
Try and do a dry run with the below input below:
10 5
-1 33 -1 -1 -1 -1 -1 120 -1 300

Correct answer is 153, your code and gfg code will give -2147483583

Try to think of an approach yourself first.

1 Like

thanx for your help . it’s working now:relaxed::relaxed: