九度 寻找大富翁

/*

 * c.cpp

 *

 *  Created on: 2013-10-7

 *      Author: wangzhu

 */



#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#include<queue>

#include<vector>

using namespace std;

int main() {

    freopen("data.in", "r", stdin);

    int n,m,k;

    while(~scanf("%d%d",&n,&m)) {

        if(0 == n && 0 == m) {

            break;

        }

        priority_queue<int,vector<int>,less<int> > p;

        for(int i = 0;i < n;i++) {

            scanf("%d", &k);

            p.push(k);

        }

        if(m > n) {

            m = n;

        }

        m --;

        printf("%d",p.top());

        p.pop();

        while(m--) {

            printf(" %d",p.top());

            p.pop();

        }

        printf("\n");

    }

    return 0;

}

 

你可能感兴趣的:(九度 寻找大富翁)