Problem: 1599. 经营摩天轮的最大利润耗时100%内存90%每次登上一个房间都需要成本旋转一圈所以当in时人数add不停累加当前可以登上房间的人数 now min(4, add)剩下的人数 add - now收入sum now * boardingCost;利润profit sum - j * runningCost;拿到最大值和对应的索引Codeclass Solution { public: int minOperationsMaxProfit(vectorint customers, int boardingCost, int runningCost) { int n customers.size(), j, sum 0, mx INT_MIN; int profit, id, add 0, now, i 0; while(i n || add 0) { if(i n) add customers[i]; j i 1; now min(4, add); add - now; sum now * boardingCost; profit sum - j * runningCost; if(profit mx) { mx profit; id j; } i; } if(mx 0) return -1; return id; } };