Minimum Preparation Time for Two Handlers
A work queue workList must be processed in order by two handlers. Each value in workList is a work type from 1 through m.
For work type t, the first time a handler processes that type, or whenever the handler's previous job was a different type, that handler pays longPrepTime[t]. If the handler's previous job was the same type, that handler pays shortPrepTime[t] instead.
Each job must be assigned to exactly one of the two handlers, and jobs must be processed in the order they appear. Return the minimum total preparation time.
Complete the function minPreparationTime in the editor below.
minPreparationTime has the following parameters:
int[] workList: the ordered work typesint[] longPrepTime: long preparation time for each work typeint[] shortPrepTime: short preparation time for each work type
Returns
int: the minimum total preparation time.
1Example 1
Assign work type 1 to the first handler, then assign both type-2 jobs to the second handler. The total cost is 4 + 5 + 3 = 12.
2Example 2
Use the same handler for all three jobs to pay one long preparation and two short preparations.
Constraints
Limits and guarantees your solution can rely on.
workList[i]identifies a work type between1andmlongPrepTimeandshortPrepTimecontain one entry per work type.- Jobs must be processed in order.