#K70612. Task Processing Based on Priority and Identifier
Task Processing Based on Priority and Identifier
Task Processing Based on Priority and Identifier
You are given n tasks, where each task is defined by a pair of integers: priority
and identifier
. Your goal is to determine the order in which the tasks will be executed.
The tasks should be sorted in descending order of their priority. In case two tasks have the same priority, they should be ordered by their identifier in ascending order.
The algorithm should output the list of task identifiers in the order of execution.
In mathematical terms, if a task is denoted by a tuple \((p, id)\), then the ordering is determined by sorting on the key:
\[ key(p, id) = \bigl(-p,\; id\bigr). \]Follow the input and output format described below.
inputFormat
The first line of input contains an integer n
(1 ≤ n ≤ 105), representing the number of tasks. Each of the following n
lines contains two space-separated integers: priority
and identifier
.
For example:
5 2 1003 1 1002 3 1001 2 1000 2 1004
outputFormat
Output a single line containing the task identifiers sorted according to the criteria provided, separated by a single space.
For the above example, the output should be:
1001 1000 1003 1004 1002## sample
1
1 1000
1000
</p>