First m big data

Source: Internet
Author: User

 

Description

Give you n integers, and output the first m in the ascending order.

Input

Each group of test data has two rows. The first row has two numbers n, m (0 <n, m <1000000), and the second row contains n different rows, and all are integers in the range.

Output

Test data in each group is output in the ascending order of the first m.

Sample Input

5 3 3-35 92 213-644

Sample Output

213 92 3 source code:
# Include <stdio. h ># include <algorithm> using namespace std; struct p {int x;} digit [1000000]; // overflow if it is defined as digit [1000000. However, struct will not overflow. // why? Bool cmp (p a, p B) {return. x> B. x ;}int main () {int M, N; while (scanf ("% d", & N, & M )! = EOF) {int I; for (I = 0; I <N; I ++) scanf ("% d", & digit [I]. x); sort (digit, digit + N, cmp); for (I = 0; I <M; I ++) {if (I = 0) printf ("% d", digit [I]. x); else printf ("% d", digit [I]. x);} printf ("\ n");} return 0 ;}

Tips:

Why ??? Why do we understand the AC as a structure? But not directly using arrays?

First m big data

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.