Problem: Changing Priorities

A scheduler hands out work to workers. Tasks arrive with a priority. While a task waits, its priority can be raised or lowered. Whenever a worker is free, it takes the highest-priority task.

public static List<String> serveOrder(String[][] events) {

}

Example:

events:
  {"add", "A", "5"}
  {"add", "B", "3"}
  {"add", "C", "8"}
  {"change", "C", "1"}   C becomes the most urgent
  {"serve"}              serves C
  {"change", "A", "2"}
  {"serve"}              serves A (priority 2, ahead of B at 3)
  {"serve"}              serves B

The answer is ["C", "A", "B"].

A plain priority queue serves the highest-priority task quickly, but it has no way to change a task’s priority once the task is in it. Think about which structure from this chapter makes each event cheap.