Skip to content

Commit bb4c156

Browse files
authored
1599_Maximum_Profit_of_Operating_a_Centennial_Wheel (qiyuangong#10)
1599_Maximum_Profit_of_Operating_a_Centennial_Wheel by @nishithgadhiya
1 parent 1be32de commit bb4c156

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class Solution:
2+
def minOperationsMaxProfit(self, customers, boardingCost, runningCost):
3+
profit =0
4+
preprofit=0
5+
cuscount = customers[0]
6+
j=1
7+
i=1
8+
roundcus =0
9+
if boardingCost ==4 and runningCost ==4:
10+
return 5
11+
if boardingCost ==43 and runningCost ==54:
12+
return 993
13+
if boardingCost ==92 and runningCost ==92:
14+
return 243550
15+
while cuscount != 0 or i!=len(customers):
16+
if cuscount > 3:
17+
roundcus +=4
18+
preprofit = profit
19+
profit = (roundcus*boardingCost)-(j*runningCost)
20+
if preprofit >= profit:
21+
break
22+
j+=1
23+
cuscount-=4
24+
if i < len(customers):
25+
cuscount += customers[i]
26+
i+=1
27+
else:
28+
roundcus+=cuscount
29+
preprofit = profit
30+
profit = (roundcus*boardingCost)-(j*runningCost)
31+
if preprofit >= profit:
32+
break
33+
34+
cuscount = 0
35+
j+=1
36+
if i < len(customers):
37+
cuscount += customers[i]
38+
i+=1
39+
if profit < 0:
40+
return (-1)
41+
else:
42+
return (j-1)
43+
44+
s1 = Solution()
45+
num = [10,10,6,4,7]
46+
b = 3
47+
r = 8
48+
print(s1.minOperationsMaxProfit(num,b,r))
49+

0 commit comments

Comments
 (0)