目录

力扣2861.最大合金数

力扣2861.最大合金数

  • 对每一台机器都做一次二分答案

cpp 复制代码
  class Solution {
  public:
      int maxNumberOfAlloys(int n, int k, int budget, vector<vector<int>>& composition, vector<int>& stock, vector<int>& cost) {
          int res = 0;
          int mx = ranges::min(stock) + budget;
          for(auto &comp : composition)
          {
              auto check = [&](long long num) -> bool
              {
                  long long ans=0;
                  for(int i=0;i<n;i++)
                      if(stock[i] < comp[i] * num)
                      {
                          ans += (comp[i] * num - stock[i]) * cost[i];
                          if(ans > budget) return false;
                      }
                  return true;
              };
              int l = res,r = mx + 1;
              while(l < r)
              {
                  int mid = l + r + 1>> 1;
                  if(check(mid)) l = mid;
                  else r = mid - 1;
              }
              res = l;
          }
          return res;
      }
  };
本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
珹洺1 分钟前
Java-servlet(完结篇)过滤器乱码解决与监听器
java·运维·服务器·hive·servlet·jsp
小开不是小可爱1 小时前
leetcode_383. 赎金信_java
java·数据结构·算法·leetcode
kill bert4 小时前
Java八股文背诵 第四天JVM
java·开发语言·jvm
√尖尖角↑4 小时前
力扣——【1991. 找到数组的中间位置】
算法·蓝桥杯
Allen Wurlitzer5 小时前
算法刷题记录——LeetCode篇(1.8) [第71~80题](持续更新)
算法·leetcode·职场和发展
百锦再6 小时前
五种常用的web加密算法
前端·算法·前端框架·web·加密·机密
你是理想7 小时前
wait 和notify ,notifyAll,sleep
java·开发语言·jvm
碳基学AI7 小时前
北京大学DeepSeek内部研讨系列:AI在新媒体运营中的应用与挑战|122页PPT下载方法
大数据·人工智能·python·算法·ai·新媒体运营·产品运营
helloworld工程师7 小时前
【微服务】SpringBoot整合LangChain4j 操作AI大模型实战详解
java·eclipse·tomcat·maven
Java&Develop7 小时前
idea里面不能运行 node 命令 cmd 里面可以运行咋回事啊
java·ide·intellij-idea