Gadget Purchases
InterviewTime limit1sMemory limit128 MB
Count how many visits demand each machine, cap each count at its usage limit, and report the machines whose revenue beats purchase plus usage cost.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Math, Sorting
- Solved
- No attempts yet
Problem
One reason health care can be so expensive is that many hospitals are equipped with very advanced — and very costly — machines. The cost of buying these machines has to be recovered somehow, typically by using them on many patients and charging each patient (or their insurance) for the usage. There are plenty of legitimate reasons to buy expensive equipment, but here we treat the purchase as a purely economic decision: figure out which machines bring in more money than they cost.
You are given a list of machines. Machine has a purchase cost , a usage cost , a maximum number of usages , and a suggested charge that the patient (or insurance) pays per usage. You pay once to buy the machine and every time you use it, while the patient pays you every time. A machine can be used at most times: if demand is higher than , only the first patients are served.
You are also given a list of patient visits; each visit names the single machine it requires. Let be the number of visits that require machine . Then machine is actually used times, earning revenue against a total expenditure of . A machine is profitable when its revenue is strictly greater than its expenditure. Determine which machines are profitable.
Input
The first line contains the number of data sets. Then follow data sets, each of the following form.
The first line of a data set contains two integers and , where is the number of patient visits and is the number of machines under consideration.
The next lines each describe one machine with four integers , , , .
The following lines each contain one integer with : the machine required by the -th visit.
Output
For each data set, first output a line Data Set x:, where is the number of the data set (starting from 1). Then output the numbers of all profitable machines, one per line, in increasing order. Separate consecutive data sets with a blank line.