Cashback
Limits: 2 sec., 512 MiB
Zenyk has planned all of his purchases for the next month, and now he and Marichka are choosing cashback categories.
The bank offers 6 different categories, and the name and the cashback percentage of each are known. Zenyk can activate exactly 2 of these categories.
Each planned purchase has a category and an amount in hryvnias. If the category of a purchase is activated, the bank returns the corresponding percentage of its amount to Zenyk. For example, for a purchase of 50 hryvnias in a category with \(3\%\) cashback he gets 1.50 hryvnias back. Purchases in other categories give no cashback. Some purchase categories may not be among the six offered by the bank.
The cashback is not capped, and nothing is rounded. Zenyk will make all the planned purchases. Find the largest total cashback he can get.
Input
Each of the first 6 lines contains a string \(s_i\) and an integer \(p_i\) – the name of the \(i\)-th available category and its cashback percentage.
The next line contains one integer \(n\) – the number of planned purchases.
Each of the next \(n\) lines contains a string \(c_i\) and an integer \(a_i\) – the category of the \(i\)-th purchase and its amount in hryvnias.
Category names consist of lowercase Latin letters. Several purchases may have the same category.
Output
Print the largest total cashback in hryvnias, with exactly 2 digits
after the decimal point, for example 12.50. The answer must
be exact.
Constraints
\(1 \le n \le 10^3\),
\(1 \le p_i \le 100\),
\(1 \le a_i \le 10^4\),
\(1 \le |s_i|, |c_i| \le 20\),
all 6 available category names are different,
there are at most 20 different names among the available categories and the purchase categories altogether.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| food 5 travel 10 books 15 clothes 3 cinema 20 medicine 7 7 food 200 travel 50 food 100 books 101 cinema 40 rent 1000 medicine 100 | 30.15 |
| Input (stdin) | Output (stdout) |
|---|---|
| food 5 travel 10 books 15 clothes 3 cinema 20 medicine 7 2 rent 1000 utilities 2000 | 0.00 |
| Input (stdin) | Output (stdout) |
|---|---|
| food 1 travel 2 books 3 clothes 4 cinema 5 medicine 6 3 medicine 1 food 1 medicine 1 | 0.13 |
Notes
In the first example, Zenyk can activate the categories
food and books. He gets 15 hryvnias for the
purchases in the food category and 15.15 hryvnias for the
purchase in the books category, 30.15 hryvnias in
total.
In the second example, neither purchase category is among the available ones, so Zenyk gets no cashback.
In the third example, Zenyk can activate the categories
medicine and food. The two purchases in the
medicine category give 12 kopiykas, and the purchase in the
food category gives 1 more kopiyka.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|