Under construction

Still being built. Things may change

Gadget Purchases

Interview

Time limit1sMemory limit128 MB

Summary
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 ii has a purchase cost pip_i, a usage cost cic_i, a maximum number of usages uiu_i, and a suggested charge rir_i that the patient (or insurance) pays per usage. You pay pip_i once to buy the machine and cic_i every time you use it, while the patient pays you rir_i every time. A machine can be used at most uiu_i times: if demand is higher than uiu_i, only the first uiu_i patients are served.

You are also given a list of patient visits; each visit names the single machine it requires. Let did_i be the number of visits that require machine ii. Then machine ii is actually used si=min⁡(di,ui)s_i = \min(d_i, u_i) times, earning revenue si⋅ris_i \cdot r_i against a total expenditure of pi+si⋅cip_i + s_i \cdot c_i. 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 KK of data sets. Then follow KK data sets, each of the following form.

The first line of a data set contains two integers nn and mm, where n≤10000n \le 10000 is the number of patient visits and m≤1000m \le 1000 is the number of machines under consideration.

The next mm lines each describe one machine with four integers pip_i, cic_i, uiu_i, rir_i.

The following nn lines each contain one integer mjm_j with 1≤mj≤m1 \le m_j \le m: the machine required by the jj-th visit.

Output

For each data set, first output a line Data Set x:, where xx 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.

Examples1

  1. Example 1

    Input
    1
    8 4
    100 0 1 150
    10000 500 1000000 5600
    500 100 2 300
    500 100 3 300
    4
    2
    3
    2
    3
    4
    3
    4
    
    Expected output
    Data Set 1:
    2
    4