getting tle even after using efficient algorithm.

Can anyone explain why am i getting tle in the below-mentioned problem?
I am using nlogn version of LIS for the problem.

link to my solution: https://ideone.com/dN56xe
link to the problem: https://www.spoj.com/problems/BRDGHRD/

Thanks in advance.