Maximum Profit of Operating a Centennial Wheel LeetCode solution in C++

1
class Solution {
2
public:
3
int minOperationsMaxProfit(vector<int> &customers, int boardingCost, int runningCost) {
4
int rotate = 0, total = 0, money = 0, num = 0, i;
5
int maxx = INT_MIN, ans = rotate;
6
for (i = 0; i < customers.size(); i++) {
7
total += customers[i];
8
rotate = i + 1;
9
if (total >= 4) {
10
num += 4;
11
total -= 4;
12
} else {
13
num += total;
14
total = 0;
15
}
16
money = num * boardingCost - rotate * runningCost;
17
if (maxx < money) {
18
maxx = money;
19
ans = rotate;
20
}
21
}
22
while (total > 0) {
23
rotate = i + 1;
24
if (total >= 4) {
25
num += 4;
26
total -= 4;
27
} else {
28
num += total;
29
total = 0;
30
}
31
money = num * boardingCost - rotate * runningCost;
32
if (maxx < money) {
33
maxx = money;
34
ans = rotate;
35
}
36
i++;
37
}
38
if (maxx < 0) return -1;
39
return ans;
40
}
41
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0