MSV: Need help understanding code

I have a simple logic for MSV.

I have implemented the logic this way:

https://www.codechef.com/viewsolution/27296690

One of my friends implemented the same logic in a slightly different way.

https://www.codechef.com/viewsolution/27280861

Mine got TLE, but her’s AC.

Can anyone help me understand the reason?