1 Star 0 Fork 0

MetaverseMobile/leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1052_爱生气的书店老板.cpp 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
class Solution {
public:
int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int X)
{
if (customers.size() <= X)
return accumulate(customers.begin(), customers.end(), 0);
int head = 0, tail = head + X - 1;
int increasement = 0;
for (int i = head; i <= tail; i++) {
if (grumpy[i])
increasement += customers[i];
}
int maxInc = increasement;
while (tail < customers.size() - 1) {
if (grumpy[head])
increasement -= customers[head];
head++;
tail++;
if (grumpy[tail])
increasement += customers[tail];
maxInc = max(increasement, maxInc);
}
int base = 0;
for (int i = 0; i < customers.size(); i++)
if (!grumpy[i])
base += customers[i];
return maxInc + base;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/MetaverseMobile/leetcode.git
[email protected]:MetaverseMobile/leetcode.git
MetaverseMobile
leetcode
leetcode
main

搜索帮助