n hours. There are two projects, and their hourly rates are given by arrays pay_a and pay_b of the same length: working on project A in hour i earns pay_a[i], working on project B earns pay_b[i].
Each hour goes to one project. Either can come first, but switching to the other project costs one hour of catching up, and that hour earns nothing.
Return the most money that can be earned over all n hours.pay_a=[6, 2, 1, 1], pay_b=[1, 1, 5, 5] → 16
Work on A in the first hour (6), spend the second hour switching, then do two hours on B (5 + 5), for 16 in total.
pay_a=[3, 3, 3], pay_b=[4, 1, 4] → 9
Switching does not pay: A alone gives 9, B alone gives 9, and any switch gives at most 7. The answer is 9.
n = pay_a.length = pay_b.lengthn ≤ 10⁵pay_a[i], pay_b[i] ≤ 10⁵pay_a=[6, 2, 1, 1], pay_b=[1, 1, 5, 5]
16
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.