CPP | Beats 100% | Clean Code | Easy Logic
Code

# Code
```cpp []
class TaskManager {
    unordered_map<int, vector<int>> taskInfo; // to store taskInfo in map as map[taskId] = {userId, priority}
    priority_queue<vector<int>> priorityInfo; // to store tasks in order of priority

public:
    TaskManager(vector<vector<int>>& tasks) {
        taskInfo.clear();
        priorityInfo = priority_queue<vector<int>>();

        // add all the tasks into the map in pq
        for(auto info : tasks){
            taskInfo[info[1]] = {info[0], info[2]};
            priorityInfo.push({info[2], info[1]});
        } 
    }
    
    // add the new tasks
    void add(int userId, int taskId, int priority) {
        taskInfo[taskId] = {userId, priority};
        priorityInfo.push({priority, taskId});
    }
    
    // edit the task in map and add a new entry into pq
    void edit(int taskId, int newPriority) {
        taskInfo[taskId] = {taskInfo[taskId][0], newPriority};
        priorityInfo.push({newPriority, taskId});
    }
    
    // remove the task
    void rmv(int taskId) {
        taskInfo.erase(taskId);
    }
    
    // remove the entry from pq if task is remove from the system of it's priority has been chnaged
    // return the userId of top task after clearing up the invalids tasks
    int execTop() {
        while(!priorityInfo.empty()){
            vector<int> topTask = priorityInfo.top();
            if(taskInfo.find(topTask[1]) == taskInfo.end() or taskInfo[topTask[1]][1] != topTask[0])
                priorityInfo.pop();
            else
                break;
        }

        if(priorityInfo.empty())
            return -1;

        int userId = taskInfo[priorityInfo.top()[1]][0];
        taskInfo.erase(priorityInfo.top()[1]);
        priorityInfo.pop();
        return userId;
    }
};

```
['C++']