hdu 1425(hash)

/*

*  hash

*/



#include <cstdio>

#include <climits>

#include <cstring>

#include <iostream>



using namespace std;



const int M = 1000001;



bool hash[M];



void init() {

    for (int i=0; i<M; ++i) hash[i] = false;

    return ; 

}



int main() {

    int n, m, maxm;

    while (scanf("%d%d", &n, &m) != EOF) {

        int p;

        init();

        maxm = INT_MIN;

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

            scanf ("%d", &p);

            p += 500000;

            hash[p] = true;

            if (p > maxm) maxm = p;

        }

        printf ("%d", maxm-500000);

        if (--m) {

            for (int i=maxm-1; i>=0; --i) {

                if (hash[i]) {

                    printf (" %d", i-500000);

                    --m;

                    if (!m) break;

                 }

            }

        }

        puts("");

    }

    return 0;

}

 

你可能感兴趣的:(hash)