One Line Hospital
20 | 78 |
通过 | 提交 |
题目描述
One Line Hospital is open now! A range of highly unusual illnesses, the likes of which you’ve never seen before. Includes: Light-headedness, Premature Mummification and Cubism! Also the hospital have many treatments for each illnesses. But there are so many patients that the hospital become crowded. Hospital Dean now ask you to write a program to arrangment patients and doctors.
There are several requirements: Every patient have a specific illness and a treatment. Hospital follow the first come first served principle, but some illness cannot wait! So we need serve the most urgent patient firstly. If there are some illness waiting in line with the same urgency, we serve the first one.
Different illnesses may have the same treatment.
输入格式
The first line contains an integer T indicating the number of test cases. For each test case:
One line contains 2 numbers n and m which means n illness(es) and m situation(s) come in order.
Each of the following n lines contains three fields:
A string indicating an illness, a string representing the treatment for this illness, a number representing the urgency of this illness. The bigger the number, the more urgent.
Each of the next m lines contains a string which can be an illness mentioned above or "next". It represents a patient with this illness come and wait in queue. If the input is "next", it means the hospital can serve the next patient and your program should output the treatment for next patient.
For every string, the length doesn't exceed 50 and doesn't contain space.
Also every number is a non-negative number and doesn't exceed 1000000000.
n,m<10000
T<10
输出格式
For each test case you should output "Case: #:" at first.
Then for each "next", you just output a treatment in one line. If the queue is empty, output "Time for break!".
样例输入 #1
1 2 6 Light-headedness Headremover 100 Mummification Decrypter 999 Light-headedness Light-headedness Mummification next next next
样例输出 #1
Case: 1: Decrypter Headremover Headremover
来源
Author JMY