自学内容网 自学内容网

力扣2530.执行K次操作后的最大分数

力扣2530.执行K次操作后的最大分数

  • move(nums)把nums移到queue里

  • push((x+2)/3) —— /3向上取整

  •   class Solution {
      public:
          long long maxKelements(vector<int>& nums, int k) {
              //把nums移到queue里,从大到小排序
              priority_queue<int> pq(less<int>(),move(nums));
              long long ans=0;
              while(k--)
              {
                  int x = pq.top();
                  pq.pop();
                  ans += x;
                  pq.push((x+2) / 3);
              }
              return ans;
          }
      };
    

原文地址:https://blog.csdn.net/Pisasama/article/details/140555373

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!