hdu 4006 The kth great number

来源:互联网 发布:日本军力知乎 编辑:程序博客网 时间:2024/05/19 19:33
#include<iostream>#include<queue>using namespace std;struct node{    int num;    friend bool operator<(node n1,node n2)    {        return n1.num>n2.num;    }};int main(){    node now,next;    priority_queue<node>q;    char c;    int n,k;    cin>>n>>k;    int m=0;    while(n--)    {        cin>>c;        if(c=='I')        {            cin>>next.num;            if(m<k)            {                q.push(next);                m++;            }            else            {                now=q.top();                if(next.num>now.num)                    {                        q.pop();                        q.push(next);                    }            }        }        else        {            now=q.top();            cout<<now.num;        }    }    return 0;}

0 0
原创粉丝点击