http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2126
典型例题,优先队列还有很多的用处,暂未开发。
#include <iostream> #include <queue> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); int n,m; while(cin>>n>>m) { priority_queue<int> a; int t = n; while(n--) { int temp; cin>>temp; a.push(temp); } if(t<m) { cout<<"ERROR"<<endl; continue; } else { while(--m) { cout<<a.top()<<' '; a.pop(); } cout<<a.top()<<endl; } } }