Hash of the first m of hdu 1280
First m Big DataTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 10574 Accepted Submission (s): 3686
Problem Description Do you still remember the assignment that Gardon assigned to John? (1005 in the last game) In fact, xiaoxi has recovered the original data table. Now she wants to confirm whether her answer is correct, but the answer is a huge table, xiaoxi only wants you to tell her the maximum M number in the answer.
Given a sequence of positive integers containing N (N <= 3000), each number cannot exceed 5000, and the N * (N-1)/2 sum of them, find the number (M <= 1000) of the First M and sort it in the ascending order.
The Input may contain multiple groups of data. Each group of data includes two rows:
The first row has two numbers N and M,
The number of N in the second row indicates the sequence.
Output outputs the number of M for each group of input data, indicating the result. The output should be arranged in ascending order.
Sample Input
4 41 2 3 44 55 3 6 4
Sample Output
7 6 5 511 10 9 9 8
Count the number of times each number appears and then output from large to small
#include
#include
int main(){ int hash[10010]; int a[3010]; int n,m; int i,j; while(scanf("%d %d",&n,&m)!=EOF) { memset(hash,0,sizeof(hash)); for(i=0;i
xx) { xx=a[i]+a[j]; } } } for(i=xx;i>=0;i--) { while(hash[i]&&m>1) { printf("%d ",i); hash[i]--; m--; } if(m==1&&hash[i]) { printf("%d\n",i); break; } } } return 0;}