Pair of roses wrong answer

https://hack.codingblocks.com/contests/c/509/696
https://ide.codingblocks.com/#/s/30949
giving wrong ans but giving right ans

https://ide.codingblocks.com/#/s/31057

I have made the required changes and commented them.
NOTE: You used a O(N^2) approach to solve this problem. But This problem can be solved in O(N) after sorting is done, using two pointer technique.

1 Like

what is label?,goto label?, never mentioned in class

what’s wrong with my code, when u added goto label statement, test case passed…
i was getting the correct output without “label”. what’s the difference?

label takes your code to the marked position.
Your code was producing multiple outputs for some test cases as that if statement was true multiple number of times. So after first output, i moved out of the loops and the if using goto label statement.