Hints — p90 Single-Threaded CPU
-
This is Shortest Job First (SJF) non-preemptive with tie-break by original index.
-
Sort tasks by
enqueueTime(keeping original index). Walk a pointer through the sorted list. -
Maintain a min-heap of (proc_time, original_idx) for ready tasks. Tuple comparison handles SJF + tie-break automatically.
-
Fast-forward: when CPU is idle (heap empty), jump
cur_timeto next task’s enqueue time. Don’t simulate every clock tick. -
Each iteration: push all arrived tasks (enqueue ≤ cur_time); pop the smallest (proc_time, idx); append idx to order; advance cur_time.
If stuck: see solution.py.