April Lunchtime 2019 Top down

Can anyone tell me how to solve this problem using Top down approach . I see alot of accepted submission using bottom up but not find any using Top down .
Question link - CodeChef: Practical coding for everyone