From 52bc75308c4732e5641c486a2b7c36bbc016f876 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Tue, 8 Oct 2024 14:40:05 +0800 Subject: [PATCH] =?UTF-8?q?2024/10/08=20=E7=81=B5=E8=8C=B6=E9=A2=98?= =?UTF-8?q?=E5=8D=95=20=E6=BB=91=E5=8A=A8=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sliding_windows/Num1052.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1052.java diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1052.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1052.java new file mode 100644 index 0000000..695dd6f --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1052.java @@ -0,0 +1,43 @@ +package com.cool.ling_cha_mount.sliding_windows; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/10/08/14:39 + * @Description: 1052. 爱生气的书店老板 + * Hard 2 + * Level 4 + * Score 1418 + */ +public class Num1052 { + + public int maxSatisfied(int[] customers, int[] grumpy, int minutes) { + int sum=0; + int non=0; + int all=0; + for(int i=0;i<minutes;i++){ + if(grumpy[i]==1){ + sum+=customers[i]; + non+=customers[i]; + } + all+=customers[i]; + } + int res=sum; + for(int i=minutes;i<customers.length;i++){ + if(grumpy[i-minutes]==1){ + sum-=customers[i-minutes]; + } + all+=customers[i]; + if(grumpy[i]==1){ + non+=customers[i]; + sum+=customers[i]; + } + res=Math.max(res,sum); + } + non-=res; + all-=non; + return all; + } + +}