Choose which subtasks an agent finishes before their deadlines

Agent buildHard40 min

Your task

A long-running research agent has a queue of subtasks to get through before its report goes out. It works on one subtask at a time, and a subtask is only worth something if it finishes by its own deadline. There is not time for all of them, so the agent has to choose.

Write best_value(subtasks) that returns the most value the agent can collect.

  • subtasks: a list of [duration, deadline, value], whole numbers. duration is how many milliseconds the subtask takes, from 1 to 1,000,000,000. deadline is the millisecond it must be finished by, counted from now, from 0 to 1,000,000,000. value is its priority score, from 0 to 100.
  • Return the largest total value, a whole number.

Rules:

  1. The agent starts at millisecond 0 and works on one subtask at a time. Once started, a subtask runs to the end without a break.
  2. A subtask counts when it finishes at or before its deadline. The agent may skip any subtask, and a skipped subtask counts for nothing.
  3. The agent may run the subtasks it picks in any order. It never needs to wait between them.
  4. There are at most 100 subtasks.

Examples

best_value(subtasks: list[list[int]]) -> int
Example 1
Inputbest_value([[3000, 4000, 5], [2000, 3000, 4], [4000, 9000, 6]])
Output11
Example 2
Inputbest_value([[500000, 500000, 10], [200000, 300000, 6], [300000, 600000, 6]])
Output12
Example 3
Inputbest_value([[4, 3, 100], [1, 1, 1], [2, 4, 3]])
Output4