P7072 直播获奖

Miku

你只需要一个小小的对顶堆

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
priority_queue <int> q1,q2; 
int n,w;
int p;
void deal(int now){
    int li=max(1,now*w/100);
    if(q1.size()>li){
        int ll=-q1.top();
        q1.pop();
        q2.push(ll);
        return ;
    }else{
        if((!q2.empty())&&(-q1.top()<q2.top())){
            int ll=-q1.top();
            int lll=q2.top();
            q1.pop();
            q2.pop();
            q2.push(ll);
            q1.push(-lll);
            return ;
        }
    }
}
int main(){
    scanf("%d%d",&n,&w);
    for(int i=1;i<=n;++i){
        scanf("%d",&p);
        q1.push(-p);
        deal(i);
        cout<<-q1.top()<<" ";
    }
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇