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