HDU1425: sort

Source: Internet
Author: User

Problem Description gives you n integers. Output The first m in the ascending order. There are two rows of test data in each Input group. The first row has two numbers n, m (0 <n, m <1000000), and the second row contains n different numbers, and all are integers in the range. Output outputs the first m of each group of test data in ascending order. Sample Input5 3 www.2cto. com3-35 92 213-644 Sample Output213 92 3 HintHint please use VC/VC ++ to submit // here the cin and cout cannot be used for input and output, [cpp] has timed out before # include <iostream> # include <cstdio> # include <algorithm> using namespace std; bool cmp (int x, int y) {return x> y;} int a [1000000]; int main () {int n, k; while (~ Scanf ("% d", & n, & k) {for (int I = 0; I <n; I ++) scanf ("% d ", & a [I]); sort (a, a + n, cmp); printf ("% d", a [0]); for (int I = 1; I <k; I ++) printf ("% d", a [I]); printf ("\ n");} return 0 ;}

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.