九度OJ 1035 09浙大真题之优先队列堆排序之《寻找大富翁》
题目地址:http://ac.jobdu.com/problem.php?pid=1034
#include<stdio.h>#include<string.h>#include<queue>using namespace std;priority_queue < int > Q;int main(){int money,m,n;while(~scanf("%d %d",&n,&m)&&n){m=m<n?m:n;while(Q.empty()==false)Q.pop();while(n--){scanf("%d",&money);Q.push(money);}if(m){money=Q.top();Q.pop();printf("%d",money);}while(--m){money=Q.top();Q.pop();printf(" %d",money);}printf("\n");}return 0;}