Skip to content

Commit 59ec737

Browse files
authored
Create 1052. Grumpy Bookstore Owner
1 parent c72eb41 commit 59ec737

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

1052. Grumpy Bookstore Owner

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int maxSatisfied(vector<int>& cust, vector<int>& grumpy, int minutes) {
4+
int res = 0, curr = 0;
5+
for(int i = 0; i < cust.size(); ++i) {
6+
if(grumpy[i] == 0) res += cust[i];
7+
}
8+
9+
for(int i = 0; i < minutes; ++i) {
10+
if(grumpy[i]) curr += cust[i];
11+
}
12+
13+
int addi = curr;
14+
for(int i = minutes; i < cust.size(); ++i) {
15+
if(grumpy[i - minutes]) curr -= cust[i - minutes];
16+
if(grumpy[i]) curr += cust[i];
17+
addi = max(addi, curr);
18+
}
19+
20+
return res + addi;
21+
}
22+
};

0 commit comments

Comments
 (0)