Plan a bisect when test runs differ in cost
Your task
A bisecting agent hunts for the commit that broke a test. Testing a commit means building it first, and builds take very different times: some hit the cache, some rebuild everything. You want the plan whose worst case finishes soonest.
Write bisect_plan(minutes) that returns the worst-case minutes of the best plan and the commit that plan tests first.
Input and output:
minutes: 1 to 150 whole numbers from 0 to 1,000,000. Commits are listed oldest first, and testing commititakesminutes[i].- Return
[worst, first].worstis the smallest possible worst-case total.firstis the index of the commit tested first by a plan with that worst case. If several commits could come first in such a plan, return the smallest index. When no test is needed, return[0, -1].
Rules:
- The commit just before commit 0 is good and the last commit is bad. Exactly one commit is the first bad one, and every commit after it is bad too.
- A test of commit
itells whetheriis good or bad, and is never wrong. - The plan chooses each test from the results so far. It stops once only one commit can be the first bad one.
- A plan's worst case is its largest total test time over every possible first bad commit.
Examples
bisect_plan(minutes: list[int]) -> list[int]Example 1
Input
bisect_plan([5, 5, 5, 5])Output
[10, 1]Example 2
Input
bisect_plan([1, 1, 1, 100, 1, 1])Output
[102, 1]Example 3
Input
bisect_plan([7])Output
[0, -1]