MINIMAX2 Unsolved question

Link: MINIMAX Problem - CodeChef
What is the optimal approach here
My code:CodeChef: Practical coding for everyone
my code just returns the elements in the subtree of each and calculate f of each pair.