From: n00m on
Have just read on their forum (see below)
but it's pretty a complex approach for me

========================================================
to solve this problem,
I used Indexed tree recorded sorted sequences.

for example)

level 0) [1, 2, 3, 4, 5, 6, 7, inf]
level 1) [1, 2, 5, 6] [3, 4, 7, inf]
level 2) [1, 5] [2, 6] [3, 7] [4, inf]
level 3) [1] [5] [2] [6] [3] [7] [4] [inf]

[...] stand for a node of indexed tree.
it works, but not enough. therefore, i got TLE.
how can i reduce execution time?

========================================================
Your algorithm is OK,
use Merge Sort to to sort sequences between levels.
========================================================