Update both ans and ans_z only when temp_ans > ans
. When temp_ans == ans, update ans_z only when z1/z2 is less than ans_z. This way you will find the minimum z which gives maximum of f(x, y, z).
thanks @techfreak_19. I am trying it. Can you please share your solution.
https://www.codechef.com/viewsolution/33026290 My code is mostly based on the editorial but the idea is same.
You can look at my AC solution on my GitHub here