Codeshow TLE

Ac solution - CodeChef: Practical coding for everyone
TLE solution - CodeChef: Practical coding for everyone
Problem Statement - CDSW154 Problem - CodeChef

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