题目比较简单,直接上代码君。
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int fir[3005];
int num[10005];
int main(){
int n,m;
while(scanf("%d%d",&n,&m)==2){
memset(num,0,sizeof(num));
for(int i=0;i<n;i++) scanf("%d",&fir[i]);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
num[fir[i]+fir[j]]++;
}
}
int i=10000;
int t=m;
while(t){
while(t&&num[i]){
if(t<m)printf(" ");
printf("%d",i);
t--;
num[i]--;
}
i--;
}
printf("\n");
}
return 0;
}