The kth great number

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.

InputThere 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. 
OutputThe 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

Hint

Xiao  Ming  won't  ask  Xiao  Bao  the  kth  great  number  when  the  number  of  the  written number is smaller than k. (1=<k<=n<=1000000).

开一个multiset(允许存在相同值的集合且加入后自动排序),维护k个元素,多出在头部删除,最后取第一个元素即可,适用于找第几大第几小的题。
#include<stdio.h>
#include<set>
using namespace std;
int main()
{
int n,k,x,i;
char c;
while(~scanf("%d%d",&n,&k)){
multiset<int> a;
for(i=;i<=n;i++){
getchar();
scanf("%c",&c);
if(c=='I'){
scanf("%d",&x);
a.insert(x);
if(a.size()>k) a.erase(a.begin());
}
else printf("%d\n",*a.begin());
}
}
return ;
}

最新文章

  1. Enterprise Integration Pattern - 组成简介
  2. 【kAriOJ】离散数学 构造群码 极大似然法解码
  3. [20130704] Intra-Query Parallel Thread Deadlocks
  4. 10条PHP编程习惯助你找工作
  5. 【Solr】数据库数据导入索引库
  6. Win7 登入提示临时漫游档案
  7. grunt-npm编译bootstrap源码
  8. 动态拼接 sql的时候 里面 如果有变量的话 按上面的方式进行处理
  9. samba常用命令
  10. LeetCode OJ 95. Unique Binary Search Trees II
  11. java应用测试报告生成(二):利用ant的build.xml生成测试报告
  12. 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本
  13. python 分支语句 循环语句
  14. UNIX环境高级编程——标准I/O库缓冲区和内核缓冲区的区别
  15. Pthon常用模块之requests,urllib和re
  16. linux重启后进入了救援模式,无法远程登录
  17. Fragment重叠,使用show和hide控制显示和隐藏界面重叠问题;
  18. vim多行注释和取消注释 Ubuntu
  19. KVM克隆CentOS6虚拟机后无法启动
  20. popen()与system()

热门文章

  1. SSH实现在WIN7系统下访问虚拟机中的Linux系统
  2. 在XP上安装VS2002
  3. Java面向对象编程(一)
  4. [省选]板块(shenben已经AFO!!!)
  5. tomcat部署web应用的4种方法以及部署多个应用
  6. bootstrap-table 行内编辑
  7. 解决Windows x64bit环境下无法使用PLSQL Developer连接到Oracle DB中的问题
  8. mongodb学习之:文档操作
  9. UVA10655 Contemplation! Algebra —— 推公式、矩阵快速幂
  10. zabbix数据库创建初始化