TLE in a codeforces problem

Link to submission : https://codeforces.com/contest/1324/submission/81004543

The method followed is similar to most of the other accepted solutions in the contest but I’m getting a TLE for test 24. Can someone tell me why is this happening?

Thanks for this, I used to think Arrays.sort uses TimSort but when in fact it is Quick Sort.