Easy Solution - HashMap with TreeMap
Complexity

Time complexity:
O(n log n)


Space complexity:
S(n)

Code

# Complexity
- Time complexity:
    O(n log n)

- Space complexity:
    S(n)

# Code
```java []
class TaskManager {
    private TreeMap<Pair<Integer, Integer>, Integer> system;
    private Map<Integer, Pair<Integer, Integer>> map;

    public TaskManager(List<List<Integer>> tasks) {
        map = new HashMap<>();
        system = new TreeMap<>(new Comparator<Pair<Integer, Integer>>() {
            @Override
            public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
                return o1.getValue().equals(o2.getValue()) ? o2.getKey() - o1.getKey() : o2.getValue() - o1.getValue();
            }
        });

        for (List<Integer> task : tasks) {
            map.put(task.get(1), new Pair<>(task.get(2), task.get(0)));
            system.put(new Pair<>(task.get(1), task.get(2)), task.get(0));
        }
    }

    public void add(int userId, int taskId, int priority) {
        map.put(taskId, new Pair<>(priority, userId));
        system.put(new Pair<>(taskId, priority), userId);
    }

    public void edit(int taskId, int newPriority) {
        Pair<Integer, Integer> p = map.get(taskId);
        Pair<Integer, Integer> rm = new Pair<>(taskId, p.getKey());
        system.remove(rm);
        map.computeIfPresent(taskId, (k, pair) -> new Pair<>(newPriority, pair.getValue()));
        system.put(new Pair<>(taskId, newPriority), p.getValue());
    }

    public void rmv(int taskId) {
        Pair<Integer, Integer> p = map.get(taskId);
        map.remove(taskId);
        Pair<Integer, Integer> rm = new Pair<>(taskId, p.getKey());
        system.remove(rm);
    }

    public int execTop() {
        Map.Entry<Pair<Integer, Integer>, Integer> entry = system.firstEntry();
        if (entry == null)
            return -1;

        int userId = entry.getValue();
        system.remove(entry.getKey());
        map.remove(entry.getKey().getKey());

        return 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();
 */
```
['Java']