标签:
优先队列,真是水的不行~
保持队列里只有K个元素即可
#include<iostream> #include<queue> using namespace std; priority_queue<int, vector<int>, greater<int> >mapp; int n,k; string cmd; int main() { while(cin>>n>>k) { while(mapp.size()) mapp.pop(); while(n--) { cin>>cmd; if(cmd=="I") { int x; cin>>x; if(mapp.size()<k) mapp.push(x); else { if(x>mapp.top()) mapp.push(x),mapp.pop(); } } else cout<<mapp.top()<<endl; } } return 0; }
标签:
原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/45199739