USING MAP
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
```cpp []
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
using namespace std;

class TaskManager {
public:
    map<int, map<int, int>> mp;  // Priority -> (TaskId -> UserId)
    unordered_map<int, int> m;  // TaskId -> Priority

    TaskManager(vector<vector<int>>& t) {
        for (int i = 0; i < t.size(); i++) {
            mp[t[i][2]][t[i][1]] = t[i][0];
            m[t[i][1]] = t[i][2];
        }
    }

    void add(int userId, int taskId, int priority) {
        mp[priority][taskId] = userId;
        m[taskId] = priority;
    }

    void edit(int taskId, int nP) {
        int user = mp[m[taskId]][taskId];  // Get the userId
        mp[m[taskId]].erase(taskId);      // Remove from current priority
        if (mp[m[taskId]].empty())        // Clean up if priority map is empty
            mp.erase(m[taskId]);
        mp[nP][taskId] = user;            // Add to new priority
        m[taskId] = nP;                   // Update taskId priority
    }

    void rmv(int taskId) {
        int priority = m[taskId];         // Get priority of the task
        mp[priority].erase(taskId);       // Remove from priority map
        if (mp[priority].empty())         // Clean up if priority map is empty
            mp.erase(priority);
        m.erase(taskId);                  // Remove from task map
    }

    int execTop() {
        if (mp.empty())                   // Check if tasks are available
            return -1;

        auto last = prev(mp.end());       // Get the highest priority
        auto inner = prev(last->second.end()); // Get the last task in that priority
        int userId = inner->second;       // Extract the userId
        int taskId = inner->first;        // Extract the taskId

        // Remove the task after execution
        last->second.erase(taskId);       
        if (last->second.empty())         // Clean up if no tasks at this priority
            mp.erase(last->first);
        m.erase(taskId);                  // Remove from task map

        return userId;                    // Return the executed 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();
 */
```
['C++']