TLE in a codeforces problem

Link to submission : Submission #81004543 - Codeforces

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.