Tle in SID problem of spoj

I am using multimap STL for the problem http://www.spoj.com/problems/SID/ . But I am getting tle. Anyone please suggest any good STL for this problem. this is my solution = http://ideone.com/ovPdH4 .

Thank You