4 4 1 2 3 4 4 5 5 3 6 4
7 6 5 5 11 10 9 9 8
#include<stdio.h>
#include<cstring>
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<n;i++)
{
scanf("%d",&a[i]);
}
int xx=0;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
hash[a[i]+a[j]]++;
if(a[i]+a[j]>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;
}
hdu 1280 前m大的数 哈希,布布扣,bubuko.com
原文地址:http://blog.csdn.net/qq_16843991/article/details/38566745