#K88007. Task Scheduling by Priority
Task Scheduling by Priority
Task Scheduling by Priority
You are given a list of tasks. Each task is represented by two integers: time_duration and priority. The tasks are provided via standard input, one task per line, and the input terminates when a line containing -1 -1
is encountered.
Your task is to sort the list of tasks in descending order of priority. If two tasks share the same priority, they must remain in the same order as they appeared in the input (i.e., sort stably by arrival order).
Note: The sorting criterion can be mathematically expressed as:
\(\text{Sort key: } (-\text{priority}, \text{arrival_index})\)
inputFormat
The input is read from standard input. Each line contains two space-separated integers representing the time_duration and priority of a task. The input ends when a line with -1 -1
is encountered. There will be at least one task before the end marker.
outputFormat
Output each sorted task on a new line. Each line should contain the time_duration and priority separated by a space.
## sample3 10
-1 -1
3 10
</p>