2 maps
Intuitionmaintain 2 maps and keep them consistent throughout the operationsApproachComplexity

Time complexity: O(nlogn)


Space complexity: O(n)

Code
# Intuition
maintain 2 maps and keep them consistent throughout the operations

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

# Complexity
- Time complexity: O(nlogn)

- Space complexity: O(n)

# Code
```cpp []
class TaskManager {
    // remove & edit task    | taskId, userId, priority 
    map<int, pair<int, int>> task; 

    // execute top           | priority, taskId, userId
    map<int, set<pair<int, int>, greater<pair<int, int>>>, greater<int>> prio; 

    void removeFromPrio(int userId, int taskId, int priority){
        prio[priority].erase(prio[priority].find({taskId, userId}));

        if(prio[priority].empty())
            prio.erase(prio.find(priority));
    }

public:

    TaskManager(vector<vector<int>>& tasks) {
        for(auto it : tasks) {
            task[it[1]] = {it[0], it[2]};
            prio[it[2]].insert(make_pair(it[1], it[0]));
        }
    }
    
    void add(int userId, int taskId, int priority) {
        vector<int> it = {userId, taskId, priority};
        task[it[1]] = {it[0], it[2]};
        prio[it[2]].insert({it[1], it[0]});
    }
    
    void edit(int taskId, int newPriority) {
        auto it = task.find(taskId);
        int userId = it->second.first;
        rmv(taskId);
        add(userId, taskId, newPriority);
    }
    
    void rmv(int taskId) {
        auto it = task.find(taskId);
        int userId = it->second.first;
        int priority = it->second.second;
        task.erase(it);
        removeFromPrio(userId, taskId, priority);
    }
    
    int execTop() {
        int ans = -1;

        if(!prio.empty()){
            auto it = prio.begin()->second.begin();
            if(it != prio.begin()->second.end()){
                ans = it->second;
                rmv(it->first);
            }
        }

        return ans;
    }
};

/**
 * 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();
 */
```
['C++']