#K92727. Intersection Order for Vehicles
Intersection Order for Vehicles
Intersection Order for Vehicles
In this problem, you are given a number of vehicles approaching an intersection. Each vehicle is described by an identifier (a string) and a priority (an integer). Your task is to determine the order in which the vehicles will cross the intersection. The vehicles are ordered first by their priority in descending order, and in case of a tie, by their identifier in lexicographically ascending order.
Formally, for two vehicles with priorities (p_i) and (p_j) and identifiers (id_i) and (id_j), vehicle (i) comes before vehicle (j) if either:
1. (p_i > p_j), or
2. (p_i = p_j) and (id_i < id_j) (in lexicographical order).
inputFormat
The first line contains an integer (n) representing the number of vehicles. Each of the next (n) lines contains a vehicle identifier (a string without spaces) and its priority (an integer), separated by whitespace.
outputFormat
Output (n) lines, each containing a vehicle identifier in the order in which the vehicles will cross the intersection.## sample
4
car1 10
car2 20
car3 10
car4 5
car2
car1
car3
car4
</p>