405543: GYM101991 C Coffee

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Coffeetime limit per test1 secondmemory limit per test1024 megabytesinputcoffee.inoutputstandard output

Given the prices of different types of coffee (latte, cappuccino, $$$\cdots$$$) for each size (small, medium, and large), and a list of orders of a group of persons. Your task is to find how much will each person pay eventually. The cost that a person needs to pay is the cost of coffee he/she ordered in addition to the delivery fees. The delivery fees for each person are $$$100\$$$$ divided by the number of persons (rounded down).

Eventually, the final cost should ignore $$$1\$$$$ greater or less than what should be paid to the nearest multiple of 5 (i.e $$$44\$$$$ and $$$46\$$$$ will be rounded to $$$45\$$$$. However, $$$47\$$$$ and $$$48\$$$$ will not be changed).

Input

The first line of the input contains a single integer $$$T$$$ specifying the number of test cases.

Each test case begins with a line containing two integers $$$C$$$ and $$$P$$$ ($$$1 \le C, P \le 100$$$), in which $$$C$$$ is the number of different types of coffees, and $$$P$$$ is the number of unique persons.

Then $$$C$$$ lines follow, giving the coffee types. Each line contains a string $$$N$$$ and three integers $$$S$$$, $$$M$$$, and $$$L$$$ ($$$1 \le S, M, L \le 100$$$), in which $$$N$$$ is a coffee name, $$$S$$$, $$$M$$$, and $$$L$$$ are the prices for small, medium, and large sizes, respectively. Each coffee type will appear exactly once per test case.

Then $$$P$$$ lines follow, giving the list of orders. Each line contains three strings $$$X$$$, $$$Y$$$, and $$$Z$$$, in which $$$X$$$ is a person name, $$$Y$$$ is the coffee size ($$$Y \in \{small,\, medium,\, large\}$$$), and $$$Z$$$ is a coffee name. It is guaranteed that all the given $$$P$$$ names are distinct, and each person will order coffee type that exists.

Both the coffee and person names are non-empty strings consisting of lowercase and uppercase English letters with a length of no more than $$$15$$$ letter.

Output

For each test case, print $$$P$$$ lines in which each line contains two space-separated values, the name of the person and the total cost he/she will pay for his/her order. Print the persons in the same order as given in the input.

ExampleInput
1
3 3
cappuccino 28 34 41
latte 25 31 38
flatwhite 26 33 47
Mohammed medium cappuccino
Mostafa large latte
Ahmad small flatwhite
Output
Mohammed 67
Mostafa 70
Ahmad 60
Note

The delivery fees is $$$100\$$$$ and divided by $$$3$$$ persons, so each of them will pay $$$\lfloor \frac{100}{3} \rfloor = 33 \$$$$.

  • The cost for "Mohammed" is $$$34\$$$$ for drinks, $$$33\$$$$ for delivery fees, this will be $$$67\$$$$, which is the final cost.
  • The cost for "Mostafa" is $$$38\$$$$ for drinks, $$$33\$$$$ for delivery fees, which will be $$$71\$$$$, then $$$1\$$$$ is ignored to the nearest multiple of 5, so the final cost is $$$70\$$$$.
  • The cost for "Ahmad" is $$$26\$$$$ for drinks, $$$33\$$$$ for delivery fees, which will be $$$59\$$$$, then $$$1\$$$$ is ignored to the nearest multiple of 5, so the final cost is $$$60\$$$$.

加入题单

上一题 下一题 算法标签: