题解 | 小红的口罩 | 优先队列贪心

小红的口罩

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

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

int main() {
    int n,k,a,ans=0;
    priority_queue<int> pq;
    cin>>n>>k;
    while(n--)cin>>a,pq.push(-a);
    while(k>=-pq.top())ans++,k-=-pq.top(),pq.push(pq.top()*2),pq.pop();
    cout<<ans<<"\n";
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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