Topic 1431:sort

Source: Internet
Author: User

Topic 1431:sort

time limit:1 seconds

Memory limit:128 MB

Special question: No

Title Description:

give you n integers, please output the number of the first m large in order from large to small.

Input:

Each set of test data has two lines, the first row has two number n,m (0<n,m<1000000), the second row contains n each are different, and are in the interval [ -500000,500000] integer.

Output:

Outputs the number of previous m large for each set of test data in order from large to small.

Sample input:
5 33-35 92 213-644
Sample output:
213 92 3
#include <iostream>#include<iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#defineOFFSET 500000using namespacestd;inthash[1000001];intMain () {intn,m;  while(SCANF ("%d%d", &n,&m)! =EOF) {         for(inti=-500000; i<=500000; i++) {Hash[i+500000]=0; }         for(intI=1; i<=n; i++)        {            intx; scanf ("%d",&x); Hash[offset+x]=1; }         for(intI=500000; i>=-500000; i--)        {            if(hash[offset+i]==1) {printf ("%d", i); M--; if(m!=0) {printf (" "); }                Else{printf ("\ n");  Break; }            }        }    }    return 0;}

Topic 1431:sort

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.