n operations I is to insert a number q is the number of the output K large
Sample Input
8 3//n K
I 1
I 2
I 3
Q
I 5
Q
I 4
Q
Sample Output
1
2
3
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <cmath>7# include <queue>8# include <list>9# define LLLong LongTen using namespacestd; One A structSS - { -FriendBOOL operator< (ConstSS A,ConstSS B) the { - if(a.v>B.V) - return 1; - Else + return 0; - } + intv; A }; at - intMain () - { - //freopen ("In.txt", "R", stdin); - intN, K; - Chars[Ten]; in while(SCANF ("%d%d", &n, &k)! =EOF) - { toPriority_queue<ss>Q; + SS T; - while(n--) the { *scanf"%s", s); $ if(s[0]=='I')Panax Notoginseng { - intA; thescanf"%d",&a); +t.v=A; A Q.push (t); the if(Q.size () >k) + { - Q.pop (); $ } $ } - Else - { theprintf"%d\n", Q.top ()); - }Wuyi } the } - Wu return 0; -}
View Code
Hdu 4006 K-Large number (priority queue)