How can I reduce execution time on my C/C++ code?

I am worried as this has happened with me 3-4 times in 2 days.MY CODE IS RIGHT but fails for big input ie. 500000.When I see others solution i cannot understand their optimised approach??What should i do …

https://www.codechef.com/ZCOPRAC/submit/ZCO14003

Actual submission link:

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

Here’s the Editorial solution:

2 Likes