Easy To Understand C++ Code | Optimized
ApproachWe use 3 data structures:

Priority Queue pq: to get task with highest priority
Format: [priority, taskId]


Map UserIdMap: to get userId for a given ta
# Approach
<!-- Describe your approach to solving the problem. -->
We use 3 data structures:
1) Priority Queue pq: to get task with highest priority
Format: [priority, taskId]

2) Map UserIdMap: to get userId for a given taskId
Format: taskId -> userId

3) Map priorityMap: to get priority for a given taskId
Format: taskId -> priority


# Code
```cpp []
class TaskManager {
public:

    priority_queue< pair<int,int> > pq;
    unordered_map<int,int> userIdMap;
    unordered_map<int,int> priorityMap;

    TaskManager(vector<vector<int>>& tasks) {
        for(auto task: tasks){
            userIdMap[task[1]]=task[0];
            priorityMap[task[1]]=task[2];
            pq.push({task[2], task[1]});
        }
    }
    
    void add(int userId, int taskId, int priority) {
        userIdMap[taskId]=userId;
        priorityMap[taskId]=priority;
        pq.push({priority, taskId});
    }
    
    void edit(int taskId, int newPriority) {
        priorityMap[taskId]=newPriority;
        pq.push({newPriority, taskId});
    }
    
    void rmv(int taskId) {
        userIdMap.erase(taskId);
        priorityMap.erase(taskId);
    }
    
    int execTop() {
        
        while(true){

            if(pq.empty()){
                return -1;
            }

            int priority=pq.top().first;
            int taskId=pq.top().second;
            pq.pop();

            if(userIdMap.find(taskId)==userIdMap.end()){
                continue;
            }
            if(priorityMap[taskId]!=priority){
                continue;
            }

            int userId=userIdMap[taskId];
            userIdMap.erase(taskId);
            priorityMap.erase(taskId);
            return userId;
        }
    }
};

/**
 * Your TaskManager object will be instantiated and called as such:
 * TaskManager* obj = new TaskManager(tasks);
 * obj->add(userId,taskId,priority);
 * obj->edit(taskId,newPriority);
 * obj->rmv(taskId);
 * int param_4 = obj->execTop();
 */
```
['Hash Table', 'Heap (Priority Queue)', 'C++']