classSolution{public:intminOperationsMaxProfit(vector<int>&customers,intboardingCost,intrunningCost){intwaiting=0;intprofit=0;intmaxProfit=0;introtate=0;intmaxRotate=-1;inti=0;while(waiting>0||i<customers.size()){if(i<customers.size())waiting+=customers[i++];// Onboard new customers.constintnewOnboard=min(waiting,4);waiting-=newOnboard;profit+=newOnboard*boardingCost-runningCost;++rotate;if(profit>maxProfit){maxProfit=profit;maxRotate=rotate;}}returnmaxRotate;}};
classSolution{publicintminOperationsMaxProfit(int[]customers,intboardingCost,intrunningCost){intwaiting=0;intprofit=0;intmaxProfit=0;introtate=0;intmaxRotate=-1;inti=0;while(waiting>0||i<customers.length){if(i<customers.length)waiting+=customers[i++];// Onboard new customers.finalintnewOnboard=Math.min(waiting,4);waiting-=newOnboard;profit+=newOnboard*boardingCost-runningCost;++rotate;if(profit>maxProfit){maxProfit=profit;maxRotate=rotate;}}returnmaxRotate;}}
Thanks for stopping by! If you find this site helpful, consider buying me some protein powder to keep me fueled! π