The problem is given here- http://opc.iarcs.org.in/index.php/problems/BOOKSORT
The problem is essentially asking for the longest increasing subsequence of the given sequence. The accepted answer here talks about how to solve this, first in O(N^2), then in O(NlogN). For the given constraints, the O(NlogN) solution is required.
Oh damn! Now I see it. Thanx.