I don’t know why am i getting TLE in 2 cases. I tried using sort function from the library and because of that i got one more testcase under TL. But I don’t get the difference between sort() function of C++ STL and heapSort() which i have implemented. I think time complexity is same for both. So, i have 2 questions to ask: (i). why there is difference in time when i use sort() from C++STL and heapsort()? (ii). Why am i getting TLE in any testcase( time complexity of the code is O(n log n) and i have seen other solutions which implemented it in just the same way)?

Problem link: https://www.codechef.com/problems/SUMQ

My Solution: https://www.codechef.com/viewsolution/14288346