Dividing Array- Greedy Algorithms

I am getting TLE in this problem. My code is at the link https://ide.codingblocks.com/s/238638. The constraints are test cases<=10 and n<=100000 and the time complexity is O(N log N). I could not understand why I am getting TLE. Please someone tell me where I am wrong in this code. What I can do to avoid TLE.