Kirana Owner's Calm Window for Maximum Happy Footfall
A busy Bengaluru kirana store owner turns grumpy during some minutes, losing those customers' goodwill. A one-time 'calm technique' keeps them composed for a fixed stretch of minutes. Choose the stretch that maximizes satisfied customers.
Problem
Given per-minute customer counts customers[i] and a binary array grumpy[i] (1 if the owner is grumpy that minute), customers are satisfied during a minute unless the owner is grumpy. A calm technique can suppress grumpiness for one contiguous block of exactly minutes consecutive minutes. Return the maximum number of satisfied customers achievable.
Input
Arrays customers and grumpy of equal length n, and an integer minutes.
Output
An integer: the maximum number of satisfied customers.
Constraints
- 1 <= n <= 2 * 10^4
- 0 <= customers[i] <= 1000
- grumpy[i] is 0 or 1; 1 <= minutes <= n
Examples
Example 1
Input
customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
Output
16
Base satisfied = 1+1+1+7 = 10; the best 3-minute calm window recovers the last 6 grumpy customers for 16.
Example 2
Input
customers = [1], grumpy = [0], minutes = 1
Output
1
Already satisfied; the technique adds nothing.