#C8029. Task Scheduling Based on Priorities

    ID: 51966 Type: Default 1000ms 256MiB

Task Scheduling Based on Priorities

Task Scheduling Based on Priorities

In this problem, you are given (n) tasks, each identified by a unique task ID and associated with a priority. You are required to schedule the tasks so that tasks with higher priorities are executed first. In case two tasks have the same priority, the task with the smaller task ID should be scheduled earlier. Your goal is to output the task IDs in the correct scheduling order.

The problem can be mathematically formulated as follows: Given a set of tasks ((id_i, p_i)) for (i = 1, 2, \ldots, n), sort the tasks such that for any two tasks (a) and (b), if (p_a > p_b) then (a) comes before (b); if (p_a = p_b) then the task with (id_a < id_b) comes first.

inputFormat

The input is given from standard input (stdin). The first line contains an integer (n) representing the number of tasks. Each of the next (n) lines contains two space-separated integers: the task ID and the priority.

For example:

5 1 2 2 4 3 3 4 4 5 1

outputFormat

Print the task IDs in the scheduled order in a single line, separated by a space. The output should be written to standard output (stdout).

For the above example, the output would be:

2 4 3 1 5## sample

5
1 2
2 4
3 3
4 4
5 1
2 4 3 1 5