Instead of SortedList use max_heap
IntuitionWe need something with O(1) or O(Log(tasks_count)) TC
So it's either external (fail during an interview :/) SortedList or heap + soft deleteComplexityY
# Intuition
We need something with O(1) or O(Log(tasks_count)) TC
So it's either **external** (fail during an interview :/) SortedList or heap + **soft delete**

# Complexity
You should know this ... by heart now

# Code
```python3 []
class TaskManager:

    def __init__(self, tasks: List[List[int]]):
        # user_id, task_id, priority
        # task is the main entity, the rest are relations
        self.task_user = defaultdict(int)
        self.task_priority = defaultdict(int)
        self.heap = [] # priority, task
        for u,t,p in tasks:
            self.task_user[t] = u
            self.task_priority[t] = p
            heappush(self.heap, (-p, -t))

    def add(self, userId: int, taskId: int, priority: int) -> None:
        self.task_user[taskId] = userId
        self.task_priority[taskId] = priority
        heappush(self.heap, (-priority, -taskId))

    def edit(self, taskId: int, newPriority: int) -> None:
        self.task_priority[taskId] = newPriority
        heappush(self.heap, (-newPriority, -taskId))

    def rmv(self, taskId: int) -> None:
        del self.task_user[taskId]
        del self.task_priority[taskId]

    def execTop(self) -> int:
        """
        pick the highest priority. if tie -> max task_id max_heap(priority,taskid)
        remove the task
        return user_id of last executed task <-- need task_user
        no tasks -> -1
        """
        while self.heap:
            p = -self.heap[0][0]
            t = -self.heap[0][1]
            # task deleted or priority changed <-- need task_priority
            if t not in self.task_priority or self.task_priority[t] != p:
                heappop(self.heap)
                continue
            u = self.task_user[t]
            self.rmv(t)
            return u
        return -1        
```
['Hash Table', 'Heap (Priority Queue)', 'Python3']