Help with CNOTE!

Unable to find any error. Please help!
Here is the link to my solution-
https://www.codechef.com/viewsolution/33371328

You have used a break statement inside a loop which is accessing input

What is wrong with that? I am unable to understand.

I have no clue what is going wrong with my code. Why is it giving a wrong answer?

It is giving wrong answer because you input some values and if you find the favourable case you break out of the loop before reading all values for a particular testcase, which results in wrong input for the next testcase.

To make it more clear…

Let’s take an example,

2
5 3 4 2
2 1
1 2
5 3 4 2
2 1
1 2

for testcase 1, you will read upto line 3, then you break out from the loop…
and now the remaining line (line 4) will be considered for the 2nd testcase…where your program goes wrong…

Solution: remove the break statement so that you read all the integers before breaking out of loop

Got it! Thanks! :smile: