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
| func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int { peopleSum := 0 curPeople := 0 i := 0 n := len(customers) curCost := 0 maxCost := 0 ans := -1 for i < n || curPeople < peopleSum { if i < n { peopleSum += customers[i] } curPeople += min(4, peopleSum - curPeople) curCost = curPeople * boardingCost - (i + 1) * runningCost if maxCost < curCost { maxCost = curCost ans = i + 1 } i++ } return ans }
func min(num1, num2 int) int { if num1 <= num2 { return num1 } return num2 }
|