view code
```py
from heapq import heappush, heappop
class Solution:
def getOrder(self, tasks: List[List[int]]) -> List[int]:
ans = []
heap = []
serial_tasks = sorted((task[0], task[1], idx) for idx, task in enumerate(tasks))
i, n, curr_time = 0, len(tasks), serial_tasks[0][0]
while i < n or heap:
while i < n and (task := serial_tasks[i])[0] <= curr_time :
heappush(heap, task[1:])
i += 1
if heap:
process_time, index = heappop(heap)
ans.append(index)
curr_time += process_time
else:
curr_time = task[0]
return ans
```
https://leetcode.com/problems/single-threaded-cpu/submissions/868150184/