← 返回 bytedance 的题目列表Task Scheduler-like with Priority Queue
类型:online_judge
Problem: Priority-Queue Based Task Scheduling (Task Scheduler-like)
You are given a list of tasks. Each task is represented by a triple:
taskId: unique identifier (string or integer)
enqueueTime: the time when the task becomes available (non-negative integer)
processingTime: time needed to execute the task (positive integer)
The system runs on a single-threaded CPU:
At any time, the CPU can run at most one task.
When the CPU is idle at time t, if multiple tasks are available (enqueueTime <= t) and not yet executed, the CPU picks one task to run.
Selection rule:
pick the task with the smallest processingTime;
if tied, pick the task with the smallest taskId (numeric or lexicographic).
Once started, a task runs to completion (non-preemptive). After running it, current time increases by processingTime.
If the CPU is idle and no tasks are available, jump current time to the next task's enqueueTime.
Output: the execution order of tasks (list of taskId in the order they start execution).
Input (stdin)
First line: integer n, number of tasks. Next n lines: taskId enqueueTime processingTime
Output (stdout)
Print n taskIds in one line separated by spaces.
Constraints
1 <= n <= 2 * 10^5
0 <= enqueueTime <= 10^9
1 <= processingTime <= 10^9
taskId can be treated as unique integers (or strings compared lexicographically).
Tests
See tests below.
Example
Input
3
1 1 2
2 2 4
3 3 2
Output
1 3 2