HDU 3785 search for monopoly

Source: Internet
Author: User

Find Monopoly Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 3541 accepted submission (s): 1503

Problem description There are n people in Wuzhen, Tongxiang, Zhejiang province. Please find the first M monopoly in this town.
The input contains multiple groups of test cases.
Each use case contains two integers, n (0 <n <= 100000) and M (0 <m <= 10). N indicates the number of people in the town, M is the number of richest people to be identified. Next, enter the wealth values of N people in the town.
If n and m are both 0, the input ends.
Output please output the number of properties of the first M richest people in Wuzhen, and the number of items in front of the multiple items. If there are less than m items, all items are output, and each group occupies one row.
Sample Input
3 12 5 -15 31 2 3 4 50 0
 
Sample output
55 4 3
 


#include<stdio.h>#include<stdlib.h>#define MAXN 100000+10int a[MAXN];int cmp(const void *b,const void *a){return *(int *)a-*(int *)b;}int main(){int n,m;while(scanf("%d%d",&n,&m)&&n!=0&&m!=0){int i,j;for(i=0;i<n;i++)scanf("%d",&a[i]);qsort(a,n,sizeof(a[0]),cmp);printf("%d",a[0]);for(j=1;j<m;j++)printf(" %d",a[j]);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.