#K84737. Magical Potion Inventory
Magical Potion Inventory
Magical Potion Inventory
You are given an inventory of magical potions. There are simple potions with fixed magical power values and complex potions whose power is computed by a recipe using simple potions. The power of a complex potion is computed according to the formula below:
\(P_{complex} = \sum_{i} (P_{i} \times n_{i})\)
Here, \(P_i\) is the power of a component potion and \(n_i\) is the corresponding count needed in the recipe.
You will be given the number of simple potions, the number of complex potions, and a sequence of brewing steps. In each brewing step, a potion (which can be simple or complex) is brewed and added to the inventory, which increases the total magical power by the power of that potion. Your task is to compute and output the cumulative total magical power after each brewing step.
inputFormat
The input is read from stdin and has the following format:
- The first line contains three integers
s
,c
, andt
representing the number of simple potions, the number of complex potions, and the number of brewing steps respectively. - The next
s
lines each contain a simple potion detail in the format:name power
(a string and an integer), wherepower
is the magical power of the potion. - The following
c
lines each contain a complex potion recipe in the format:name: comp1 count1, comp2 count2, ...
, meaning that the complex potionname
has components where eachcomp
is a potion name andcount
is the number of times that component is used. The power of a complex potion is the weighted sum of its components' power values. - The next
t
lines each contain the name of a potion (a simple or complex potion) that is brewed during that step.
outputFormat
For each of the t
brewing steps, output a single line to stdout containing one integer: the cumulative total magical power in the inventory after that step.
3 0 3
healing 10
mana 20
strength 15
healing
mana
strength
10
30
45
</p>