Dividing Array - Greedy Algorithms

I have submitted the code at the link https://ide.codingblocks.com/s/238514. It is showing TLE. The constraints are test cases<=10 and n<=100000. The complexity of this algorithm is O(N log N). Could not understand how to avoid TLE.

@ankur8632,
[2*i+1] can be out of bound. Make sure it isn’t.