Your question is DP Problem with Factory Lines. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
A.O. Smith is scheduling sequential assembly stages for a ProLine water heater. Each stage can run on either of two factory lines, but processing times differ by line, some line-stage combinations may be unavailable, and moving between lines incurs a transfer cost.
Return the minimum total completion time and one line assignment that achieves it.
Implement optimize_factory_lines(processing, transfer, start), where:
processing is a list of n two-element lists. processing[i][line] is the time for stage i on the specified line. A value of -1 means that assignment is unavailable.transfer is a list of n - 1 2-by-2 matrices. transfer[i][previous_line][next_line] is the cost of moving from the line used for stage i to the line used for stage i + 1.start is a two-element list containing the initial cost of entering each line before stage 0.Return a dictionary with time, the minimum total time, and lines, a list of n integers containing the selected line for each stage. If no complete assignment exists, return {"time": -1, "lines": []}. Any optimal assignment is acceptable.
def optimize_factory_lines(processing, transfer, start):