MINIMAX2 Unsolved question

Link: https://www.codechef.com/problems/MINIMAX
What is the optimal approach here
My code:https://www.codechef.com/viewsolution/28398321
my code just returns the elements in the subtree of each and calculate f of each pair.