How do I solve the problem Nested Candy Boxes(AMBOXES) from CodeChef?

I was trying to solve this problem but could not get much intuition to proceed. This is what I thought so far : Try traversing all the levels, compare the maximum number of candies on that level, with the required number of candies, if the maximum number of candies on that level exceeds the number required, obtain the answer by dividing it with number of candies each box contains on that level. But I am not sure if my approach is correct, can anyone help me out with this? I tried looking at the successful submissions but no luck.