题解 | 小红的口罩

小红的口罩

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;
}

全部评论

相关推荐

迷茫的大四🐶:价格这么低都能满了?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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