Order tasks through a researcher and a writer agent

Agent buildHard35 min

Your task

Your report pipeline runs every task through a researcher agent and then a writer agent. The researcher gathers sources, the writer drafts, and each handles one task at a time. You choose the order the tasks go through the pipeline and want the last draft done as early as possible.

Write earliest_finish(tasks) that returns the earliest minute at which the writer can finish every task.

Input and output:

  • tasks: up to 100,000 tasks, each [research, write]: the minutes the researcher and the writer spend on it, whole numbers from 0 to 1,000,000,000.
  • Return a whole number of minutes, counted from minute 0. With no tasks, return 0.

Rules:

  • Both agents take the tasks in the same order, the one you choose, and both start at minute 0.
  • The researcher starts each task as soon as it finishes the one before.
  • The writer starts a task once the researcher has finished it and the writer has finished the task before it.
  • Neither agent stops partway through a task.

Examples

earliest_finish(tasks: list[list[int]]) -> int
Example 1
Inputearliest_finish([[30, 10], [10, 40]])
Output60
Example 2
Inputearliest_finish([[5, 5], [5, 5], [5, 5]])
Output20
Example 3
Inputearliest_finish([[20, 5], [15, 30], [40, 25], [10, 10], [25, 35]])
Output120