C++ Easy to understand map and set approach
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 []
// Custom comparator for the set to sort by the first element in descending order
struct CompareSet {
    bool operator()(const std::pair<int, int>& a, const std::pair<int, int>& b) const {
        return a.first > b.first;  // Sort pairs in descending order based on first element
    }
};
struct CompareMap {
    bool operator()(const int& a, const int& b) const {
        return a > b;  // Reverse the default order (descending)
    }
};
class TaskManager {
public:
 
int mxpriority=0;
   std::map<int, std::set<std::pair<int, int>, CompareSet>, CompareMap> pr;
  unordered_map<int,int>tp;
    TaskManager(vector<vector<int>>& tasks) {
       for(int i=0;i<tasks.size();i++){
        pr[tasks[i][2]].insert({tasks[i][1],tasks[i][0]});
        tp[tasks[i][1]]=tasks[i][2];
       }
    }
    
    void add(int userId, int taskId, int priority) {
         pr[priority].insert({taskId,userId});
         tp[taskId]=priority;
    }
    
    void edit(int taskId, int newPriority) {
        int prevpr=tp[taskId];
        std::set<std::pair<int, int>, CompareSet>& mySet = pr[prevpr];
        auto it = mySet.find({taskId, 0});
        int userid=it->second;
        mySet.erase(it);
        if( mySet.size()==0)
        pr.erase(prevpr);
        tp[taskId]=newPriority;
        pr[newPriority].insert({taskId,userid});
    }
    
    void rmv(int taskId) {
         int prevpr=tp[taskId];
       std::set<std::pair<int, int>, CompareSet>& mySet=pr[prevpr];
        auto it = mySet.find({taskId, 0});
         mySet.erase(it);
         if( mySet.size()==0)
        pr.erase(prevpr);
         tp.erase(taskId);
    }
    
    int execTop() {
        if(pr.size()==0)
        return -1;
       int toppr=pr.begin()->first;
       std::set<std::pair<int, int>, CompareSet>& mySet=pr[toppr];
       int ans=mySet.begin()->second;
       mySet.erase(mySet.begin());
        if( mySet.size()==0)
        pr.erase(toppr);
        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();
 */
```
['Hash Table', 'Design', 'Ordered Set', 'C++']