4 4 1 2 3 4 4 5 5 3 6 4
7 6 5 5 11 10 9 9 8
<span style="font-size:24px;">#include <iostream> #include<algorithm> using namespace std; int a[3005],s[10000]; int cmp(int a,int b) { return a>b; } int main() { int n,m,i,j; while(~scanf("%d%d",&n,&m)) { memset(s,0,sizeof(s)); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n,cmp); int t=0,p=0; if(n>100) t=100; else t=n; for(i=0;i<t;i++) for(j=i+1;j<t;j++) s[p++]=a[i]+a[j]; sort(s,s+p,cmp); for(i=0;i<m-1;i++) cout<<s[i]<<" "; cout<<s[i]<<endl; } return 0; } </span>
原文地址:http://blog.csdn.net/u012766950/article/details/38071453