Choose which subtasks an agent finishes before their deadlines
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.durationis how many milliseconds the subtask takes, from 1 to 1,000,000,000.deadlineis the millisecond it must be finished by, counted from now, from 0 to 1,000,000,000.valueis its priority score, from 0 to 100.- Return the largest total value, a whole number.
Rules:
- 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.
- A subtask counts when it finishes at or before its deadline. The agent may skip any subtask, and a skipped subtask counts for nothing.
- The agent may run the subtasks it picks in any order. It never needs to wait between them.
- There are at most 100 subtasks.
Examples
best_value(subtasks: list[list[int]]) -> intExample 1
Input
best_value([[3000, 4000, 5], [2000, 3000, 4], [4000, 9000, 6]])Output
11Example 2
Input
best_value([[500000, 500000, 10], [200000, 300000, 6], [300000, 600000, 6]])Output
12Example 3
Input
best_value([[4, 3, 100], [1, 1, 1], [2, 4, 3]])Output
4