CHPINTU video solution | Pintu and fruits

Video tutorial for CHPINTU problem asked in march long challenge.
link -

1 Like
please tell what is wrong in my code.Its running normally in my pc but here it is showing wrong answer.

It is showing wrong answer. Read the hidden traps in the editorial.

but in sample case output is coming fine.

Okay try

2 3
1 2
0 1

Is it 0?
Just because it gives correct output for the sample cases, doesn’t mean your program is correct.

the answer should be 1?

No. It’s 0. Fruit 1 has a basket, and costs the least. Instead of checking whether it’s 0, you need to check whether there’s a basket or not.

Your code is not giving the right answer. Try running it for
6 4
1 2 3 3 2 2
0 3 9 1 1 1
Your code gives ans=5, correct ans should be 0, because fruit1 exists which has price 0, so you have to take it into consideration. If the fruit list didnot have fruit1, then we have to ignore it in the answer, then the correct ans would be 5.
now why is it wrong?

Your code is still giving wrong answer, try running it for
6 4
1 2 1 2 3 3
2 3 9 1 1 1
your code gives ans=4 whereas it should be 2.
Tip: try running your code on several test cases to find the mistake. also your code is having O(n^2) complexity, this can be done in O(n).

i know i am really irritating but this time i have tried many test cases but still wa.

Check your code its giving wrong answer, you have big value for temp which may throw a warning. also its printing random character /n in the end, replace it with either endl or \n.

thank you so much finally i got the answer my main mistake was i used variable s as a test case variable and then again used s as a counter variable.Again thanx for help.