PAIRING Getting time limit exceeded

Can somebody tell me at which point in my code am i doing unnecessary computation because I am getting TLE for this solution.And if it is optimized then is the reason for getting TLE is due to use of inefficient i/o method?Please help…
My code-
http://www.codechef.com/viewsolution/4943912

//