There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently handle adding, modifying, executing, and removing tasks.
Implement the
TaskManager
class:
TaskManager(vector<vector<int>>& tasks)
initializes the task manager with a list of user-task-priority triples. Each element in the input list is of the form[userId, taskId, priority]
, which adds a task to the specified user with the given priority.void add(int userId, int taskId, int priority)
adds a task with the specifiedtaskId
andpriority
to the user withuserId
. It is guaranteed thattaskId
does not exist in the system.void edit(int taskId, int newPriority)
updates the priority of the existingtaskId
tonewPriority
. It is guaranteed thattaskId
exists in the system.void rmv(int taskId)
removes the task identified bytaskId
from the system. It is guaranteed thattaskId
exists in the system.int execTop()
executes the task with the highest priority across all users. If there are multiple tasks with the same highest priority, execute the one with the highesttaskId
. After executing, thetaskId
is removed from the system. Return theuserId
associated with the executed task. If no tasks are available, return -1.Note that a user may be assigned multiple tasks.
1 |
|