Bali Pairs getting TLE, Submission #5120164

I submitted Bali pairs but I am getting TLE. According to me my complexity is O(2*n), but then also TLE

Submission #5120164

@prikshit.bit please provide me code in coding block IDE.

https://ide.codingblocks.com/s/199961 here is the link to the code

@prikshit.bit do a little dry run of code and you will see the complexity is n^2 not 2*n.
A little piece of advice don’t use such big templates, especially if you are a beginner, it make debugging code difficult, and you might face a bit issue in company tests also as their you would not be able to use such snippets.

Here is code for the problem you can refer.
If this resolves your doubt mark it as resolved.

@Abhinav Singh could you please send me the recursive code

@Abhinav Singh Yes I am beginner with 5 stars on codechef and expert on codeforces

@prikshit.bit you seemed to have taken the suggestion wrong way, anyways.
Here is recursive code


If this resolves your doubt mark it as resolved.