You have balls and colours. Each ball will have a specific colour and a specific value. You are only allowed to take balls of each colour. Given queries of , What is the maximum total value that you can achieve?
Input Specification
The first line will contain , and , the number of balls, number of colours and the number of queries, respectively. The next lines will each contain a string and integer , the colour and value of the ball. The string will only contain capital and lowercase letters. The next lines will each contain one integer , the maximum number of balls you can pick from each colour.
Subtask 1 [30%]
Subtask 2 [70%]
No further constraints.
Output Specification
For each query, print the maximum total value that you can achieve by taking at most balls from each colour.
Note that you may have to use long for this problem.
Sample Input 1
6 3 2
Red 5
Green 2
Red 8
Blue 4
Blue 0
Green 3
1
2
Sample Output 1
15
22
Sample Explanation 1
By taking of each ball, we can get a total value of . For of each ball, we take all of them to get a total value of .
Comments