forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.1599
No.1599.Maximum Profit of Operating a Centennial Wheel
- Loading branch information
Showing
6 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Solution { | ||
public: | ||
int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) { | ||
int ans = -1; | ||
int mx = 0, t = 0; | ||
int wait = 0, i = 0; | ||
while (wait || i < customers.size()) { | ||
wait += i < customers.size() ? customers[i] : 0; | ||
int up = min(4, wait); | ||
wait -= up; | ||
++i; | ||
t += up * boardingCost - runningCost; | ||
if (t > mx) { | ||
t = mx; | ||
ans = i; | ||
} | ||
} | ||
return ans; | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int { | ||
ans := -1 | ||
t, mx := 0, 0 | ||
wait, i := 0, 0 | ||
for wait > 0 || i < len(customers) { | ||
if i < len(customers) { | ||
wait += customers[i] | ||
} | ||
up := min(4, wait) | ||
wait -= up | ||
t += up*boardingCost - runningCost | ||
i++ | ||
if t > mx { | ||
mx = t | ||
ans = i | ||
} | ||
} | ||
return ans | ||
} | ||
|
||
func min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} |
19 changes: 19 additions & 0 deletions
19
solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Solution { | ||
public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) { | ||
int ans = -1; | ||
int mx = 0, t = 0; | ||
int wait = 0, i = 0; | ||
while (wait > 0 || i < customers.length) { | ||
wait += i < customers.length ? customers[i] : 0; | ||
int up = Math.min(4, wait); | ||
wait -= up; | ||
++i; | ||
t += up * boardingCost - runningCost; | ||
if (t > mx) { | ||
mx = t; | ||
ans = i; | ||
} | ||
} | ||
return ans; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Solution: | ||
def minOperationsMaxProfit( | ||
self, customers: List[int], boardingCost: int, runningCost: int | ||
) -> int: | ||
ans = -1 | ||
mx = t = 0 | ||
wait = 0 | ||
i = 0 | ||
while wait or i < len(customers): | ||
wait += customers[i] if i < len(customers) else 0 | ||
up = min(wait, 4) | ||
wait -= up | ||
t += up * boardingCost - runningCost | ||
i += 1 | ||
if t > mx: | ||
mx = t | ||
ans = i | ||
return ans |