这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1280
我直接用的STL的priority_queue做的~~~
#include
#include
using namespace std;
int N, M;
int arr[3005];
int main()
{
//freopen("input.txt", "r", stdin);
priority_queue pq;
while(scanf("%d %d", &N;, &M;) != EOF)
{
for(int i=0; i<N; ++i)
scanf("%d", &arr[i]);
for(int i=0; i<N; ++i)
for(int j=i+1; j<N; ++j)
pq.push(arr[i]+arr[j]);
for(int i=0; i<M; ++i)
{
if(i != 0)
printf(" ");
printf("%d", pq.top());
pq.pop();
}
printf("\n");
}
}