标签:
题意:排序
思路:排序
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int a[4500005]; bool cmp(int a,int b){ return a>b;//降序 } int main(){ int b[3005]; int n,m,i,j,k; while(~scanf("%d%d",&n,&m)){ k=0; for(i=0;i<n;++i) scanf("%d",&b[i]); for(i=0;i<n;++i) for(j=i+1;j<n;++j) a[k++]=b[i]+b[j]; sort(a,a+k,cmp); for(i=0;i<m-1;++i) printf("%d ",a[i]); printf("%d\n",a[i]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/bofengyu/p/4729574.html