N boys are standing in the assembly. There is a single line only. Boys are denoted by their roll num…

Click here to read the complete problem statement.

If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

This submission didn’t get CLE because of using Python. You need to figure out the optimal solution to this problem. A naive approach here will result in this regardless of the programming language.

@Nabil62245 I have solved this problem using python perfectly.
Brute force like approach will not work here.
Try to find a more efficient way to solve the problem.

I can’t figure out where the problem of my program is. I passed every single test case except for the last one. They say it’s exceeded CPU limit. My RAM is okay at 84 MB. But what can I do to make my program go faster? PLEASE HELP!

A brute force like approach is likely to get a CPU Limit Exceeded verdict for this problem even if you use faster languages like C / C++ / Pascal. The test cases are very big so you will most likely get succeed if you calculate the odds mathematically.

So, try to find a better way to solve the problem and avoid looping.