hdu 1280

来源:互联网 发布:stc单片机价格 编辑:程序博客网 时间:2024/06/02 11:39

//2487654 2010-05-25 10:27:01 Accepted 1280 15MS 280K 1090 B C++ T&T
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
//int res[4500100];
int main()
{
 int b,t;
 int j;
 int n,m,num[3005],i;
 int sum;
 int hash[10001];
 while(scanf("%d%d",&n,&m) != EOF)
 { 
  sum = 0;
  b = 0;
  memset(hash,0,sizeof(hash));
  for( i =0; i <n; i++)
  {
   scanf("%d",&num[i]);
  }
  //sort(num,num + n,cmp);
  for(i = 0; i < n -1; i++)
  {
   for( j = i + 1; j < n; j++)
   {
   sum =num[i] + num[j];
   hash[sum]++; 
   }
  }
  
  //sort(res,res + b,cmp);
  for(i = 10000; i >= 0; i--)
  {
   if(hash[i] != 0)
   {
    if(hash[i] == 1)
    {
     printf("%d",i);
     b++;
     if(b != m)
     {
      printf(" ");
     }
    }
    else
    {
     for(j = 0; j < hash[i]; j++)
     {
      printf("%d",i);
      b++;
      if(b != m)
      {
       printf(" ");
      }
      if(b == m)
      {
       break;
      }
     }
    }
    
   }
   if(b == m)
   {
    break;
   }
  }
  printf("/n");
 }
}