A help desk serves visitors[i] people in minute i. The clerk is in a bad mood during minutes where moody[i] == 1, and every visitor served in a moody minute leaves unhappy; visitors in other minutes leave happy. You have one goodwill token that keeps the clerk cheerful for a block of exactly k consecutive minutes (the token's minutes count as not moody). Return the maximum number of happy visitors you can achieve by choosing when to use the token.
Examples
Input: visitors = [2, 0, 3, 4, 1, 5, 2], moody = [0, 1, 1, 0, 1, 1, 0], k = 2
Output: 14
Explanation: use the token for minutes 4 and 5. Minutes 0, 3 and 6 are happy anyway
(2 + 4 + 2 = 8) and the token rescues 1 + 5 = 6 more.
Input: visitors = [4], moody = [1], k = 1
Output: 4
Constraints
1 <= k <= len(visitors) == len(moody) <= 10**50 <= visitors[i] <= 1000,moody[i]is0or1- Target complexity: O(n) time; recomputing the total for each token position is too slow for the largest tests.
Goals
- Separate the guaranteed part of the answer from the part a window can change
- Maximise a fixed-size window sum over a derived array