http://acm.hdu.edu.cn/showproblem.php?pid=1280

普通方法(625ms)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int b[3000*1501];
int cmp(const void *a,const void *b)
{
    return *(int *)b-*(int *)a;
}
int main()
{
    int n,m;
    int a[3001];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int k=0;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
                b[k++]=a[i]+a[j];
        }
        qsort(b,k,sizeof(b[0]),cmp);
        printf("%d",b[0]);
        for(int i=1;i<m;i++)
        {
                printf(" %d",b[i]);

        }
        printf("\n");
    }
    return 0;
}
View Code

相关文章:

  • 2021-10-05
  • 2022-12-23
  • 2021-11-30
  • 2021-07-03
  • 2021-07-05
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-31
  • 2021-06-04
  • 2022-02-03
  • 2021-09-23
  • 2022-12-23
  • 2022-02-11
相关资源
相似解决方案