-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution1052.cs
47 lines (40 loc) · 1.03 KB
/
Solution1052.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution1052
{
/// <summary>
/// 1052. Grumpy Bookstore Owner - Medium
/// <a href="https://leetcode.com/problems/grumpy-bookstore-owner</a>
/// </summary>
public int MaxSatisfied(int[] customers, int[] grumpy, int minutes)
{
var satisfied = 0;
var max = 0;
var current = 0;
var left = 0;
var right = 0;
while (right < customers.Length)
{
if (grumpy[right] == 0)
{
satisfied += customers[right];
}
else
{
current += customers[right];
}
if (right - left + 1 > minutes)
{
if (grumpy[left] == 1)
{
current -= customers[left];
}
left++;
}
max = Math.Max(max, current);
right++;
}
return satisfied + max;
}
}