Fast Approach to solve this in C++
ApproachThe TaskManager class manages tasks using a priority queue and an unordered map. Tasks are stored in the map with their priority and user details, while
# Approach
The `TaskManager` class manages tasks using a priority queue and an unordered map. Tasks are stored in the map with their priority and user details, while the priority queue ensures they are ordered by priority. Tasks can be added, edited, or removed, and the highest-priority task is executed by checking the priority queue and validating the task. If the task is still valid, it is executed and removed; otherwise, the next task is checked.
<!-- The `TaskManager` class manages tasks using a priority queue and an unordered map. Tasks are stored in the map with their priority and user details, while the priority queue ensures they are ordered by priority. Tasks can be added, edited, or removed, and the highest-priority task is executed by checking the priority queue and validating the task. If the task is still valid, it is executed and removed; otherwise, the next task is checked. -->

# Complexity
- Time complexity: 
Constructor: O(m log m)
Add: O(log n)
Edit: O(log n)
Remove: O(1)
Execute Top: O(n log n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class TaskManager {
private:
    unordered_map<int, pair<int, int>> taskDetails;
    struct CompareTask {
        bool operator()(const pair<int, int>& a, const pair<int, int>& b) {
            if (a.first != b.first) {
                return a.first < b.first;
            }
            return a.second < b.second;
        }
    };
    priority_queue<pair<int, int>, vector<pair<int, int>>, CompareTask> pq;
public:
    TaskManager(vector<vector<int>>& tasks) {
        for (const auto& task : tasks) {
            int userId = task[0];
            int taskId = task[1];
            int priority = task[2];
            taskDetails[taskId] = {priority, userId};
            pq.push({priority, taskId});
        }
    }
    void add(int userId, int taskId, int priority) {
        taskDetails[taskId] = {priority, userId};
        pq.push({priority, taskId});
    }
    void edit(int taskId, int newPriority) {
        taskDetails[taskId].first = newPriority;
        pq.push({newPriority, taskId});
    }
    void rmv(int taskId) {
        taskDetails.erase(taskId);
    }
    int execTop() {
        while (!pq.empty()) {
            int priority = pq.top().first;
            int taskId = pq.top().second;
            pq.pop();
            auto it = taskDetails.find(taskId);
            if (it != taskDetails.end() && it->second.first == priority) {
                int userId = it->second.second;
                taskDetails.erase(taskId);
                return userId;
            }
        }
        return -1;
    }
};


/**
 * 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++']