Maximum Payout with Context Switches
Learn this problemProblem statement
You are given two arrays, payoutA and payoutB, of equal length. Index i represents one task slot in a fixed sequence. In that slot, you may skip the slot, complete Startup A's task for payoutA[i], or complete Startup B's task for payoutB[i].
You may complete at most maxTasks tasks. Every completed task costs one day. If a completed task belongs to a different startup than the previous completed task, it also costs one idle context-switch day. Skipped slots consume no days and do not change the startup of the previous completed task.
The total number of task days plus context-switch days must not exceed days. Return the maximum total payout. Choosing no tasks is allowed and yields 0.
Function
maximumPayout(payoutA: int[], payoutB: int[], maxTasks: int, days: int) → longExamples
Example 1
payoutA = [5,1,10]payoutB = [1,8,2]maxTasks = 2days = 2return = 15Complete Startup A's tasks in slots 0 and 2. They cost two task days, require no context switch, and pay 5 + 10 = 15.
Example 2
payoutA = [5,1,10]payoutB = [1,8,2]maxTasks = 2days = 3return = 18Complete Startup B's task in slot 1 and Startup A's task in slot 2. The two tasks and one switch consume three days, and the payout is 8 + 10 = 18.
Example 3
payoutA = [7,4]payoutB = [6,9]maxTasks = 0days = 4return = 0No task may be completed when maxTasks is 0, so the maximum payout is 0.
Constraints
1 <= payoutA.length = payoutB.length <= 1000 <= payoutA[i], payoutB[i] <= 10^90 <= maxTasks <= payoutA.length0 <= days <= 2 * payoutA.length