Time Limit Exceeding in two questions

For two questions my code is getting TLE even when my solution is following the editorial. Could anyone elaborate my problem ,is the problem with I/O
http://discuss.codechef.com/questions/7269/firesc-editorial
http://www.codechef.com/viewsolution/2896103


http://www.codechef.com/viewsolution/2889549