This is how I solved it. The official solution is pretty similar. For each ingredient Qij in each package you can compute the number of kits, that you can create using it. For instance if the optimal recipe requires 100g of tomato and you have 1100g, than you can create 10, 11 or 12 kits. Notice this will always be an interval, in this case [10, 12]. You can compute the interval boundaries using a little bit of math.
After converting each Qij to an interval, you want to find intervals, that overlap. E.g. you can combine the onion interval [9-10] with the tomato interval [10-12], because 10…