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 …

Actual submission link:

Here’s the Editorial solution: