#C9591. Maximum Tower Height
Maximum Tower Height
Maximum Tower Height
You are given n blocks, where each block is characterized by its height and color. You are also given q queries. For each query, determine the maximum possible tower height that can be achieved by summing the heights of all blocks of the queried color.
If there are no blocks matching the queried color, the answer is 0.
The total height for a query color is computed as follows:
$$ S = \sum_{i=1}^{n} h_i \cdot \mathbf{1}(c_i = query) $$
where \(h_i\) is the height of the \(i\)-th block, \(c_i\) is its color, and \(\mathbf{1}(\cdot)\) is the indicator function.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers, n and q, representing the number of blocks and the number of queries, respectively.
- The next n lines each contain an integer and a string, representing the height and color of a block.
- The following q lines each contain a string denoting a query color.
outputFormat
Output to standard output (stdout) exactly q lines. Each line should contain an integer representing the total height of all blocks that have the queried color.
## sample5 3
10 red
15 blue
20 red
5 blue
25 green
red
blue
yellow
30
20
0
</p>