关闭

The kth great number

116人阅读 评论(0) 收藏 举报
分类:

Description

Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to help Xiao Bao.

Input

There are several test cases. For each test case, the first line of input contains two positive integer n, k. Then n lines follow. If Xiao Ming choose to write down a number, there will be an " I" followed by a number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao Bao, there will be a "Q", then you need to output the kth great number.

Output

The output consists of one integer representing the largest number of islands that all lie on one line.

Sample Input

8 3
I 1
I 2
I 3
Q
I 5
Q
I 4
Q

Sample Output

1
2
3


 #include <iostream>
 #include <algorithm>
 #include <string>
 #include <queue>
 using namespace std;
 struct Node
 {
     int x;
     friend bool operator < (Node a,Node b)
    {
        return a.x > b.x;
    }
  };
int main()
 {
    int T,k;
     while(cin>>T>>k)
     {
         priority_queue <Node> q;
         int mark_k = 0;
         while(T--)
         {
             char ch;
             cin>>ch;
             if(ch == 'I')
             {
                if(mark_k < k)
                {
                     Node num;
                     mark_k++;
                     cin>>num.x;
                     q.push(num);
                 }
                 else
                 {
                    Node num;
                     cin>>num.x;
                    if(num.x > q.top().x)
                    {
                        q.pop();
                         q.push(num);
                     }
                 }
             }
             else
            {
                if(ch == 'Q')
                 {
                     cout<<q.top().x<<endl;
                }
             }
         }
    }
     return 0;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:89537次
    • 积分:2431
    • 等级:
    • 排名:第15940名
    • 原创:165篇
    • 转载:14篇
    • 译文:0篇
    • 评论:34条
    最新评论