heap
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
from heapq import heappop, heappush
from collections import defaultdict
class TaskManager:

    def __init__(self, tasks: List[List[int]]):
        self.task={}
        
        self.priority=[]
        for a,b,c in tasks:
            self.task[b]=[c,a]
            heappush(self.priority,(-c,-b,a))


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


    def edit(self, taskId: int, newPriority: int) -> None:
        self.task[taskId]=[newPriority,self.task[taskId][1]]
        heappush(self.priority,(-newPriority,-taskId,self.task[taskId][1]))

    def rmv(self, taskId: int) -> None:
        self.task[taskId]=[None,None]
        

    def execTop(self) -> int:
        while self.priority and (self.task[-self.priority[0][1]][1]!=self.priority[0][2] or self.task[-self.priority[0][1]][0]!=-self.priority[0][0]):
            heappop(self.priority)
        if  self.priority:
            self.task[-self.priority[0][1]]=[None,None]
            us=self.priority[0][2]
            heappop(self.priority)
            return us
        return -1    

        


# Your TaskManager object will be instantiated and called as such:
# obj = TaskManager(tasks)
# obj.add(userId,taskId,priority)
# obj.edit(taskId,newPriority)
# obj.rmv(taskId)
# param_4 = obj.execTop()
```
['Python3']