Codeshow TLE

Ac solution - http://www.codechef.com/viewsolution/6351130
TLE solution - http://www.codechef.com/viewsolution/6352489
Problem Statement - http://www.codechef.com/problems/CDSW154

Why 1st solution is accepted while 2nd is giving TLE , though both are same ???