Find greater element

can you tell me how to optimize this solution
https://ide.codingblocks.com/s/79177 due to TLE in 2nd test case

please accept the request chat option

how to get off tle from the second case