Please simply link to your submission, rather than taking a screenshot of it and telling us what your code does (although it’s great that you described the high-level logic of it :))
This fellow:
was seeing a similar pattern - AC on the second subtasks, but TLE on the (more constrained) first subtask. Maybe something to do with the number of testcases? Dunno
Even I havent figured it out why (I faced the same problem)
So I just went with a bruteforce approach when l<=10 (Subtask 1)
It worked so I am not complaining !
Logic:
compute the recipe to whom it belongs in linear time.
calculate the numerator part of solution and denominator part of solution for the final ratio.
multiply result variable with numerator and divide by denominator to take care of overflow.