There is a bookstore owner whose store is open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers where customers[i] is the number of customers that enter the store at the start of minute i, and an integer array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during minute i, or 0 otherwise.
When the bookstore owner is grumpy, the customers of that minute are not satisfied. Otherwise, they are satisfied.
The bookstore owner knows a secret technique that, when used, keeps the owner from being grumpy for minutes consecutive minutes. The technique can only be used once.
Return the maximum number of customers that can be satisfied throughout the day.
Function Signature
def max_satisfied(customers: list[int], grumpy: list[int], minutes: int) -> int:
Rules
-
Minutes are numbered from 0, and
customers[i]
and
grumpy[i]
both describe minute
i
.
-
The technique covers exactly
minutes
consecutive minutes that lie inside the day, so it starts at some minute
s
with
0 <= s <= n - minutes
.
-
The customers of a minute count once, whether they are satisfied because the owner was calm anyway or because the technique covered that minute.
Constraints
-
n == len(customers) == len(grumpy)
-
1 <= n <= 2 * 10^4
-
0 <= customers[i] <= 1000
-
grumpy[i]
is either
0
or
1
-
1 <= minutes <= n
Examples
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
Output: 16
Without the technique, minutes 0, 2, 4 and 6 satisfy 1 + 1 + 1 + 7 = 10 customers. Using the technique on minutes 5 to 7 also satisfies the customers at grumpy minutes 5 and 7, which adds 1 + 5 = 6, for a total of 16.
Input: customers = [1], grumpy = [0], minutes = 1
Output: 1
There is one minute and the owner is not grumpy, so the single customer is satisfied.
Input: customers = [4,10,10], grumpy = [1,1,0], minutes = 2
Output: 24
Minute 2 already satisfies 10 customers. Using the technique on minutes 0 and 1 satisfies the other 4 + 10 = 14, so all 24 customers are satisfied.