C++ Simple std::map + std::set
Complexity

Time complexity:
n = number of active tasks
Constructor - O(n∗log(n))
Add - O(log(n))
Edit - O(log(n))
Remove - O(log(n))
ExecTop - O(log(n))


Spac
# Complexity
- Time complexity:
`n = number of active tasks`
**Constructor - $O(n*log(n))$**
**Add - $O(log(n))$**
**Edit - $O(log(n))$**
**Remove - $O(log(n))$**
**ExecTop - $O(log(n))$**

- Space complexity: $O(n)$ where $n$ denoted number of active tasks.

# Code
```cpp []
using ar = array<int, 2>;
class TaskManager {
private:
    set<ar, greater<>> allTasks; // {priority, taskId}
    map<int, array<int, 2>> data; // <taskId, {user, priority}>
public:
    TaskManager(vector<vector<int>>& tasks) {
        for(auto& task : tasks) add(task[0], task[1], task[2]);
    }
    
    void add(int userId, int taskId, int priority) {
        allTasks.insert({priority, taskId});
        data[taskId] = {userId, priority};
    }
    
    void edit(int taskId, int newPriority) {
        allTasks.erase({data[taskId][1], taskId});
        data[taskId][1] = newPriority;
        allTasks.insert({data[taskId][1], taskId});
    }
    
    void rmv(int taskId) {
        allTasks.erase({data[taskId][1], taskId});
        data.erase(taskId);
    }
    
    int execTop() {
        if(allTasks.empty()) return -1;
        int taskId = (*allTasks.begin())[1];
        int user = data[taskId][0];
        rmv(taskId);
        return user;
    }
};
```
['C++']