当前位置:网站首页>力扣------经营摩天轮的最大利润
力扣------经营摩天轮的最大利润
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;
}
边栏推荐
- Modifiers of attributes of TS public, private, protect
- Prior knowledge of machine learning in probability theory (Part 1)
- 请查收.NET MAUI 的最新学习资源
- MySQL InnoDB Architecture Principle
- Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
- selenium 获取dom内验证码图片
- postgres 建立连接并删除记录
- MYSQL IFNULL使用功能
- 示波器探头对信号源阻抗的影响
- shell编程100例
猜你喜欢
Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
Teach yourself to train pytorch model to Caffe (I)
张丽俊:穿透不确定性要靠四个“不变”
LeetCode_哈希表_困难_149. 直线上最多的点数
请查收.NET MAUI 的最新学习资源
What should I do to prepare for the interview algorithm position during school recruitment?
Display DIN 4102-1 Class B1 fire test requirements
Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
uni-app 蓝牙通信
leetcode:1139. The largest square bounded by 1
随机推荐
终端安全能力验证环境搭建和渗透测试记录
MySQL deep paging optimization with tens of millions of data, and online failure is rejected!
请查收.NET MAUI 的最新学习资源
systemd-resolved 开启 debug 日志
判断横竖屏的最佳实现
基于flask写一个接口
Cross end solution to improve development efficiency rapidly
Selenium gets the verification code image in DOM
Aitm 2-0003 horizontal combustion test
ODPs next map / reduce preparation
Golang(1)|从环境准备到快速上手
Clion-MinGW编译后的exe文件添加ico图标
AITM2-0002 12s或60s垂直燃烧试验
The primary key is set after the table is created, but auto increment is not set
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
Traps in the explode function in PHP
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
postgres 建立连接并删除记录
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
字典树简单入门题(居然是蓝题?)