← 返回 scale.ai 的题目列表Task Processor: Schedule tasks by deadline using a priority queue
类型:online_judge
Problem: Task Processor (schedule tasks by deadline)
You are given a list of tasks tasks. Each task has:
task_id: a unique identifier
deadline: an integer deadline (smaller means more urgent)
Implement a Task Processor that outputs the processing order under these rules:
Always process the task with the smallest deadline first.
If multiple tasks have the same deadline, process them in the same order as they appear in the input (stable ordering).
Input (stdin)
First line: integer n, number of tasks.
Next n lines: two integers task_id deadline.
Output (stdout)
Print one line with the task_ids in processing order, separated by spaces.
Constraints
1 <= n <= 2 * 10^5
task_id are positive, unique
deadline is a non-negative 32-bit integer
Example
Input:
5
1 10
2 5
3 7
4 5
5 12
Output:
2 4 3 1 5
Example
Input
5
1 10
2 5
3 7
4 5
5 12
Output
2 4 3 1 5