Description

A bookstore owner has customers arriving each minute. They are grumpy sometimes but can keep calm for k minutes. Maximize satisfied customers.

Examples

Input:customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
Output:16
Explanation:

Optimal window maximizes satisfaction.

Input:customers = [4,10,10], grumpy = [1,1,0], minutes = 2
Output:24
Explanation:

Without using the technique, only customers at index 2 are satisfied (10 customers). By making the owner non-grumpy for 2 consecutive minutes at indices 0-1, it is possible to satisfy all customers: 4 + 10 + 10 = 24 total satisfied customers.

Input:customers = [2,6,6,9], grumpy = [0,0,1,1], minutes = 1
Output:17
Explanation:

Initially, customers at indices 0 and 1 are satisfied (2 + 6 = 8). It is possible to make the owner non-grumpy for 1 minute. Choosing index 3 (9 customers) gives us the maximum gain. Total satisfied customers: 2 + 6 + 9 = 17.

Constraints

  • 1 ≤ customers.length ≤ 2 × 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!