spoj - scuba diver - TLE - solved

i tested my code with several inputs, works correct but gives TLE on spoj,
problem - http://www.spoj.com/problems/SCUBADIV/
my code - http://ideone.com/jjFJ2p
AC code - http://ideone.com/uqtYAR
thanx ,…:slight_smile: