这个问题有很多博客讨论了,这里是STL拯救世界,直接构造出了优先序列。以后还是认真看看这个问题吧。
// Problem#: 19855
// Submission#: 4951919
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
priority_queue<int, vector<int>, greater<int> > pq;
bool marked[20000002];
int main() {
int n, k, data;
cin >> n >> k;
while(n--) {
cin >> data;
if(marked[data + 10000000]) continue;
else {
marked[data + 10000000] = true;
pq.push(data);
}
if(pq.size() > k) pq.pop();
}
cout << pq.top() << endl;
return 0;
}