Maximum Profit of Operating a Centennial Wheel LeetCode solution in Python

1
import sys
2

3
MIN_INT = -sys.maxsize - 1
4

5

6
class Solution:
7
def minOperationsMaxProfit(
8
self, customers: List[int], boardingCost: int, runningCost: int
9
) -> int:
10
maxx = MIN_INT
11
rotate = total = ans = money = num = i = 0
12
for i in range(len(customers)):
13
total += customers[i]
14
rotate = i + 1
15
if total >= 4:
16
num += 4
17
total -= 4
18
else:
19
num += total
20
total = 0
21
money = num * boardingCost - rotate * runningCost
22
if maxx < money:
23
maxx = money
24
ans = rotate
25
i += 1
26
while total > 0:
27
rotate = i + 1
28
if total >= 4:
29
num += 4
30
total -= 4
31
else:
32
num += total
33
total = 0
34
money = num * boardingCost - rotate * runningCost
35
if maxx < money:
36
maxx = money
37
ans = rotate
38
i += 1
39
if maxx < 0:
40
return -1
41
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0