Easy to understand C++ Solution using only Map🔥, Beats 100%
Beats 100%Code
## Beats 100%
![image.png](https://assets.leetcode.com/users/images/93b91080-89aa-4277-bcc5-4890e86457d4_1736013614.288424.png)

# Code
```cpp []
class TaskManager {
public:
    map<int, pair<int, int>> taskInfo;  
    // Maps taskId -> {userId, priority} to store task details.

    map<int, map<int, int>> priorityMap; 
    // Maps priority -> {taskId -> userId} to group tasks by priority.

    // Constructor to initialize the task manager with a list of tasks.
    TaskManager(vector<vector<int>>& tasks) {
        for (auto& task : tasks) {
            int userId = task[0], taskId = task[1], priority = task[2];
            taskInfo[taskId] = {userId, priority};  // Store task details.
            priorityMap[priority][taskId] = userId; // Group task by priority.
        }
    }

    // Adds a new task with userId, taskId, and priority.
    void add(int userId, int taskId, int priority) {
        taskInfo[taskId] = {userId, priority};  // Add task to taskInfo.
        priorityMap[priority][taskId] = userId; // Add task to priorityMap.
    }

    // Edits the priority of an existing task.
    void edit(int taskId, int newPriority) {
        auto [userId, oldPriority] = taskInfo[taskId]; // Get current task details.

        // Remove task from the old priority group.
        priorityMap[oldPriority].erase(taskId);
        if (priorityMap[oldPriority].empty()) {
            priorityMap.erase(oldPriority); // Remove empty priority group.
        }

        // Update task details and add to the new priority group.
        taskInfo[taskId] = {userId, newPriority};
        priorityMap[newPriority][taskId] = userId;
    }

    // Removes a task by its ID.
    void rmv(int taskId) {
        auto [userId, priority] = taskInfo[taskId]; // Get task details.

        // Remove task from the priority group.
        priorityMap[priority].erase(taskId);
        if (priorityMap[priority].empty()) {
            priorityMap.erase(priority); // Remove empty priority group.
        }

        // Erase task from taskInfo.
        taskInfo.erase(taskId);
    }

    // Executes the task with the highest priority.
    int execTop() {
        if (priorityMap.empty()) return -1; // Return -1 if no tasks exist.

        // Get the highest priority group (last element in priorityMap).
        auto it = prev(priorityMap.end());
        int priority = it->first;

        // Get the last task in the highest-priority group.
        auto taskIt = prev(it->second.end());
        int taskId = taskIt->first;
        int userId = taskIt->second;

        // Remove the task from the priority group and taskInfo.
        it->second.erase(taskIt);
        if (it->second.empty()) {
            priorityMap.erase(priority); // Remove empty priority group.
        }
        taskInfo.erase(taskId);

        return userId; // Return the userId associated with the executed task.
    }
};


```
![upvote please.png](https://assets.leetcode.com/users/images/e52238d3-b882-45b6-933c-c02b27bb0a63_1736013473.1043622.jpeg)

['Hash Table', 'Design', 'Ordered Map', 'Sorting', 'C++']