#K44552. Task Scheduling by Priority and Time

    ID: 27556 Type: Default 1000ms 256MiB

Task Scheduling by Priority and Time

Task Scheduling by Priority and Time

You are given a set of tasks, each represented by two integers \(p\) and \(t\), where \(p\) is the priority and \(t\) is the execution time of the task. The goal is to determine the execution order by sorting the tasks primarily by descending priority and secondarily by ascending execution time.

More formally, for two tasks \((p_i, t_i)\) and \((p_j, t_j)\), task \(i\) comes before task \(j\) if:

  • \(p_i > p_j\), or
  • \(p_i = p_j\) and \(t_i < t_j\)

Your program should read the input from standard input and output the sorted tasks to standard output, each task on its own line in the format "p t".

inputFormat

The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), the number of tasks.

The following \(n\) lines each contain two integers \(p\) and \(t\), separated by a space, where \(p\) (priority) and \(t\) (execution time) describe a task.

You can assume that all integers are within reasonable limits such that they can be processed efficiently.

outputFormat

Output \(n\) lines. Each line should contain two integers \(p\) and \(t\), representing a task, in the order of execution defined as above.

## sample
5
3 5
1 2
1 3
2 1
3 2
3 2

3 5 2 1 1 2 1 3

</p>