Grumpy Bookstore OwnerLeetcode Problem 1052
英文原题
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0. 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 to keep themselves not grumpy for X minutes straight, but can only use it once.
Return the maximum number of customers that can be satisfied throughout the day.
Example 1:
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3 Output: 16 Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
中文翻译
今天,书店开店 customers.length 分钟。
每分钟,有 customers[i] 个人进入书店,并且在这分钟结束时全都离开了书店。
在有些时间(某几分钟),书店店长心情不好。
如果书店店长在 第 i 分钟心情不好,那么 grumpy[i] = 1,否则 grumpy[i] = 0。
当书店店长 心情不好的时候,那一分钟的客户也不开心,反之,客户就开心。
然而书店店长,知道服用板蓝根能让自己连续 X 分钟 不 心情不好(也就是一直心情好),但这板蓝根只能服用一次。
请你返回 这一天能让最多消费者开心的数量。
样例
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3 Output: 16 解释:店长决定在最后 3 分钟 服用 板蓝根 所以能让消费者开心的最多人数是 = 1 + 1 + 1 + 1 + 7 + 5 = 16.
问题签名
Java 代码
1 2 3 4 5 class Solution { public int maxSatisfied(int[] customers, int[] grumpy, int X) { }}
Java Script 代码
1 2 3 4 5 6 7 8 9 /*** @param {number[]} customers* @param {number[]} grumpy* @param {number} X* @return {number}*/var maxSatisfied = function(customers, grumpy, X) { };
Python 代码
1 2 class Solution: def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int: