-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (38 loc) · 1.3 KB
/
main.cpp
File metadata and controls
49 lines (38 loc) · 1.3 KB
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
48
49
//go:build ignore
#include <bits/stdc++.h>
using namespace std;
int maxSatisfied(vector<int> customers, vector<int>grumpy, int minutes) {
int totalCustomers = 0;
int totalUnsatisfiedCustomers = 0;
for (int i = 0; i < customers.size(); i++) {
totalCustomers += customers[i];
customers[i] *= grumpy[i];
totalUnsatisfiedCustomers += customers[i];
}
int left = 0;
int right = left + minutes - 1;
int satisfiedCustomersInRage = 0;
for (int i = left; i <= right; i++)
{
satisfiedCustomersInRage += customers[i];
}
int maxSatisfiedCustomers = satisfiedCustomersInRage;
while (right < customers.size() -1) {
satisfiedCustomersInRage -= customers[left];
left++;
satisfiedCustomersInRage += customers[right + 1];
right++;
maxSatisfiedCustomers = max(maxSatisfiedCustomers, satisfiedCustomersInRage);
}
return totalCustomers - totalUnsatisfiedCustomers + maxSatisfiedCustomers;
}
int main() {
vector<int> customers {1,0,1,2,1,1,7,5};
vector<int> grumpy {0,1,0,1,0,1,0,1};
int minutes = 3;
// vector<int> customers {10,1,7};
// vector<int> grumpy {0,0,0};
// int minutes = 2;
cout << maxSatisfied(customers, grumpy, minutes) << endl; // 16 (1 + 1 + 1 + 7 + 5
return 0;
}