当前位置:网站首页>力扣------经营摩天轮的最大利润
力扣------经营摩天轮的最大利润
2022-07-05 21:20:00 【qq_37760746】

int minOperationsMaxProfit(int* customers, int customersSize, int boardingCost, int runningCost){
int Record=0;
int top=0;
int stack[1000000];
int count=0;
int max=-10000;
int index;
for(int a=0;a<customersSize;a++){
Record=Record+customers[a];
if(Record>4){
count=count+4*boardingCost-runningCost;
stack[top++]=count;
Record=Record-4;
}
else{
count=count+customers[a]*boardingCost-runningCost;
stack[top++]=count;
Record=0;
}
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
}
if(Record>0){
while(1){
if(Record>4){
count=count+4*boardingCost-runningCost;
stack[top++]=count;
Record=Record-4;
}
else{
count=count+Record*boardingCost-runningCost;
stack[top++]=count;
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
break;
}
if(stack[top-1]>max){
max=stack[top-1];
index=top-1;
}
}
}
if(max<=0){
return -1;
}
return index+1;
}
边栏推荐
猜你喜欢

面试官:并发编程实战会吗?(线程控制操作详解)

示波器探头对信号源阻抗的影响

MySQL deep paging optimization with tens of millions of data, and online failure is rejected!

Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)

张丽俊:穿透不确定性要靠四个“不变”

Display DIN 4102-1 Class B1 fire test requirements

Talk about my fate with some programming languages

秋招将临 如何准备算法面试、回答算法面试题

Influence of oscilloscope probe on measurement bandwidth

Opérations de lecture et d'écriture pour easyexcel
随机推荐
示波器探头对测量带宽的影响
《SAS编程和数据挖掘商业案例》学习笔记# 19
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
PHP deserialization +md5 collision
Mode - "Richter replacement principle"
Clion configures Visual Studio (MSVC) and JOM multi-core compilation
Cross end solution to improve development efficiency rapidly
Reading and writing operations of easyexcel
Dictionary tree simple introductory question (actually blue question?)
Pytorch实战——MNIST数据集手写数字识别
Simple interest mode - evil Chinese style
Determine the best implementation of horizontal and vertical screens
R语言【数据管理】
示波器探头对信号源阻抗的影响
当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
Is it necessary for bazel to learn
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
EasyExcel的读写操作
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
Is Kai Niu 2980 useful? Is it safe to open an account