How to overcome TLE problem ? for https://www.codechef.com/LTIME64B/problems/CHEFRES

Here is my solution :

https://www.codechef.com/viewsolution/20403131

i think complexity of this solution is O(T*(nlogn+mlogn) , which should not exceed time limit of 1sec.
but i am getting tle.
HELP ME asap


this solultion is matka| sattamatka| kalyan makta| open to close