题解 | 小红的口罩

小红的口罩

https://www.nowcoder.com/practice/fde642522d664b49a10fe9de51686026

优先队列

#include <iostream>
#include<queue>
#include<vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    priority_queue<int,vector<int>,greater<int>>heap;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        heap.push(a);
    }
    int total=0;
    int day=0;
    while(!heap.empty()){
        int t=heap.top();
        heap.pop();
        total+=t;
        if(total>k)break;
        day++;
        heap.push(2*t);
    }
    cout<<day<<endl;
    return 0;
}

全部评论

相关推荐

小浪_Coding:1. 个人技能排版太乱, 写的技术栈太浅了, 跟测试,自动化相关的太少; 2. 项目开发类的太简单没有亮点, 算法类的项目建议只放一个,最好有自动化,CI/CD, pipline的项目, 需要更换; 3.整体排版需要优化, SOOB打招呼都需要注意等.
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务