Each dish has a minimum cost and the prestige that goes with that cheapest way; pick a subset of dishes with total cost at most B maximizing prestige, then report the smallest cost achieving it.
Medium7Dynamic programmingGraphShortest pathSortingNo attempts yetTime limit4sMemory limit512 MB
A chef who wants a Michelin star plans to present a selection of her signature dishes to the inspectors. She has a budget B for the total cost of that selection, and she wants the total prestige of the dishes she presents to be as large as possible.
The chef keeps a list of recipes together with their costs and ingredients. One recipe turns a base dish into a derived dish by adding one ingredient. A recipe also records the cost of applying it, on top of the cost of the base dish, and the prestige it adds to the prestige of the base dish. The chef counts prestige in her own unit, the prestige unit.
A recipe list for pizza looks like this.
pizza_tomato pizza_base tomato 1 2
pizza_classic pizza_tomato cheese 5 5
pizza_base is an elementary dish. No recipe produces it, so its cost is 0 and its prestige is 0. Adding tomato to pizza_base gives pizza_tomato for 1 euro and 2 prestige units. Adding cheese to pizza_tomato gives pizza_classic for 5 more euros and 5 more prestige units, so pizza_classic has total cost 6 and total prestige 7.
A selection may contain both pizza_tomato and pizza_classic. That selection has total prestige 9 and total cost 7.
Given the recipe list and the budget B, maximize the total prestige of the selection while its total cost stays at most B.
Rules
Limits
Print two lines, each with one integer. On the first line print the largest total prestige reachable within the budget. On the second line print the smallest total cost that reaches that total prestige. This cost is at most B.