You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.
You are given an array customers of length n where customers[i] is the number of new customers arriving just before the ith rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.
You can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.
Return the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.
Example 1:

Input: customers = [8,3], boardingCost = 5, runningCost = 6
Output: 3
Explanation: The numbers written on the gondolas are the number of people currently there.
Example 2:
Input: customers = [10,9,6], boardingCost = 6, runningCost = 4
Output: 7
Explanation:
Input: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92
Output: -1
Explanation:
Constraints:
每次从 customers 拿到新到的顾客数量放到 waiting 缓冲区中,然后我们从 waiting 缓冲区中至多拿 4 个来计算收益,如果当前收益超过过去的最大收益则记录下收益和当前圈数
impl Solution {
pub fn min_operations_max_profit(
mut customers: Vec<i32>,
boarding_cost: i32,
running_cost: i32,
) -> i32 {
let mut waiting = customers.remove(0);
let mut max_profit = 0;
let mut max_rotate = 0;
let mut curr = 0;
let mut rotates = 0;
while waiting > 0 || !customers.is_empty() {
let actual = waiting.clamp(0, 4);
waiting -= actual;
curr += boarding_cost * actual - running_cost;
rotates += 1;
if curr > max_profit {
max_profit = curr;
max_rotate = rotates;
}
waiting += if !customers.is_empty() {
customers.remove(0)
} else {
0
}
}
if max_rotate == 0 {
-1
} else {
max_rotate
}
}
}