#K55337. Transfer Order
Transfer Order
Transfer Order
You are given a series of labs, each containing a number of chemicals. Each chemical has an associated weight. The chemicals are to be transferred from the labs to a central storage facility. The priority of transferring a chemical is determined primarily by its weight and secondarily by the lab's name (in case of a tie in weight, the lab with the lexicographically smaller name is prioritized).
Formally, for each lab with name \(L\), number of chemicals \(c\), and weight \(w\), add \(c\) entries of \(L\) to a list. Then, sort the list based on the following criteria:
- Higher weight first (i.e. sort in descending order by \(w\)).
- If weights are equal, sort in ascending lexicographical order by lab name.
Your task is to determine and output the resulting transfer order for each test case.
inputFormat
The first line of input contains a single integer \(T\) representing the number of test cases. Each test case has the following format:
- A line containing a single integer \(n\) denoting the number of labs.
- Then, \(n\) lines follow. Each of these lines contains a lab's information in the format:
name count weight
, where: name
is a string representing the lab's name.count
is an integer representing the number of chemicals in the lab.weight
is an integer indicating the weight capacity of each chemical.
outputFormat
For each test case, output a single line consisting of the lab names (each repeated as many times as the number of chemicals in that lab) arranged in the order they will be transferred. The names must be separated by a single space.
## sample3
3
LABA 3 10
LABB 2 20
LABC 4 5
2
LABX 1 100
LABY 2 50
3
LABA 1 10
LABC 1 10
LABB 1 10
LABB LABB LABA LABA LABA LABC LABC LABC LABC
LABX LABY LABY
LABA LABB LABC
</p>