what is wrong in my solution

question link: http://www.spoj.com/problems/ALIEN/

solution link: https://ideone.com/V0Jqkf

Please explain your logic… as it will help the people helping you a lot… I know how easy it is to just give problem and soln but ur small effort will help a lot… thanks…

If sum>x while traversing then we store sum before it exceeds x and maintain start and end whose difference provides the number of stations traversed and we are taking their maximum.if sum=x and number of stations traversed is maximum we store sum as number of people seen.if finally sum is less than x we give a final check.