Editorial for COCI '07 Regional #3 Kuhar


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Let us first solve the following subproblem: how many dollars must we pay to buy G units of some ingredient?

This subproblem is easily solved by trying all possible numbers of large packages and calculating the number of small packages needed to achieve G units. The solution is the smallest cost over all choices for the number of large packages.

Now we can check if we have enough ingredients for S servings of the meal. For each ingredient, we know how many units we need for S servings and we can calculate the cost for that many servings using the above algorithm. If we have enough money to buy all needed ingredients, then we can prepare S servings.

A solution that increments S while we can prepare S servings will score 90\% of points. To obtain the full score, use binary search to find the largest S such that we can prepare S servings.


Comments

There are no comments at the moment.