-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path1052.Grumpy-Bookstore-Owner.py
More file actions
38 lines (32 loc) · 951 Bytes
/
1052.Grumpy-Bookstore-Owner.py
File metadata and controls
38 lines (32 loc) · 951 Bytes
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
# https://leetcode.com/problems/grumpy-bookstore-owner/
# Medium (46.84%)
# Total Accepted: 2,136
# Total Submissions: 4,560
# beats 100.0% of python submissions
class Solution(object):
def maxSatisfied(self, customers, grumpy, X):
"""
:type customers: List[int]
:type grumpy: List[int]
:type X: int
:rtype: int
"""
minutes = len(customers)
if X == minutes:
return sum(customers)
res = 0
for i in xrange(minutes):
if grumpy[i] == 0:
res += customers[i]
cur = 0
for i in xrange(X):
if grumpy[i] == 1:
cur += customers[i]
tmp = cur
for i in xrange(X, minutes):
if grumpy[i] == 1:
cur += customers[i]
if grumpy[i - X] == 1:
cur -= customers[i - X]
tmp = max(tmp, cur)
return tmp + res