Problem - https://hack.codingblocks.com/contests/c/537/52
My Code - https://ide.codingblocks.com/s/37577
The code is running in IDE but shows runtime error in the contest in some cases and Time Limit exceeded in some other cases with slight modifications. How can I improve it to make it more time efficient?