Description

Given m sequences, each contains n non-negative integer. Now we may select one number from each sequence to form a sequence with m integers. It's clear that we may get n ^ m this kind of sequences. Then we can calculate the sum of numbers in each sequence, and get n ^ m values. What we need is the smallest n sums. Could you help us?

Input

The first line is an integer T, which shows the number of test cases, and then T test cases follow. The first line of each case contains two integers m, n (0 < m <= 100, 0 < n <= 2000). The following m lines indicate the m sequence respectively. No integer in the sequence is greater than 10000.

Output

For each test case, print a line with the smallest n sums in increasing order, which is separated by a space.

Sample Input

1
2 3
1 2 3
2 2 3

Sample Output

3 3 4
 #include"iostream"
#include"algorithm"
#include"ctime"
#include"cstdio"
#include"cctype"
using namespace std;
#define maxx 2008
int a[maxx],b[maxx],sum[maxx];
int main()
{
int i,j,k,t,n,m,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(i=;i<m;i++)
{
sort(a,a+n);
for(j=;j<n;j++)
scanf("%d",&b[j]);
for(j=;j<n;j++)
sum[j]=a[j]+b[];
make_heap(sum,sum+n);
for(j=;j<n;j++)
for(k=;k<n;k++)
{
temp=b[j]+a[k];
if(temp>=sum[])
break;
pop_heap(sum,sum+n);
sum[n-]=temp;
push_heap(sum,sum+n);
}
for(j=;j<n;j++)
a[j]=sum[j];
}
sort(a,a+n);
printf("%d",a[]);
for(j=;j<n;j++)
printf(" %d",a[j]);
printf("\n");
printf("time :%d\n",clock());
}
return ;
}

Sequence用堆排序的更多相关文章

  1. 1306.Sequence Median(堆排序)

    1306 URAL真是没水题 以为简单的排序就好了 ME  内存限制很紧 堆排序 或者 STL 用堆排序做的 正好复习一下 都忘了 #include <iostream> #include ...

  2. 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅶ(延伸:堆排序的实现)

    2.4.5 堆排序 我们可以把任意优先队列变成一种排序方法.将所有元素插入一个查找最小元素的有限队列,然后再重复调用删除最小元素的操作来将他们按顺序删去.用无序数组实现的优先队列这么做相当于进行一次插 ...

  3. PAT A1098 Insertion or Heap Sort (25 分)——堆排序和插入排序,未完待续。。

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  4. PAT甲级——1098 Insertion or Heap Sort (插入排序、堆排序)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90941941 1098 Insertion or Heap So ...

  5. PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]

    题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...

  6. 算法与数据结构(十四) 堆排序 (Swift 3.0版)

    上篇博客主要讲了冒泡排序.插入排序.希尔排序以及选择排序.本篇博客就来讲一下堆排序(Heap Sort).看到堆排序这个名字我们就应该知道这种排序方式的特点,就是利用堆来讲我们的序列进行排序.&quo ...

  7. [数据结构]——堆(Heap)、堆排序和TopK

    堆(heap),是一种特殊的数据结构.之所以特殊,因为堆的形象化是一个棵完全二叉树,并且满足任意节点始终不大于(或者不小于)左右子节点(有别于二叉搜索树Binary Search Tree).其中,前 ...

  8. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  9. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

随机推荐

  1. Multiple reportviewers on one page With reportviwer 11.0

    Hi,  evreryone: When I use  VS 2012  to create report with reportviwer 11.0, I  meet a  problem abou ...

  2. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  3. Android 添加系统服务

    原创文章,转载请注明出处:http://blog.csdn.net/t5721654/article/details/7480696 Android系统本身提供了很多系统服务,如WindowManag ...

  4. 了解RFC协议号

    RFC是Request For Comment的缩写,意即“请求注解”,是由IETF管理,所有关于Internet的正式标准都以文档出版,但不是所有的RFC都是正式的标准,很多RFC的目的只是为了提供 ...

  5. HDU4456-Crowd(坐标旋转+二位树状数组+离散化)

    转自:http://blog.csdn.net/sdj222555/article/details/10828607 大意就是给出一个矩阵 初始每个位置上的值都为0 然后有两种操作 一种是更改某个位置 ...

  6. HDU 1702 http://acm.hdu.edu.cn/showproblem.php?pid=1702

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> #define ...

  7. final static T

    /** * An empty table instance to share when the table is not inflated. */ static final Entry<?,?& ...

  8. 学习php 韩顺平

    1.动态语言的发展史 最早使用cgi 学习 apache  全世界最流行的web服务器 php运行流程 → apache→php文件→数据库→php文件→浏览器 php底层语言是c语言 jsp底层语言 ...

  9. 对同一元素设置overflow-x:hidden,overflow-y:visible;属性值不生效

    作者:孙志勇 微博 日期:2016年12月5日 一.时效性 所有信息都具有时效性.文章的价值,往往跟时间有很大关联.特别是技术类文章,请注意本文创建时间,如果本文过于久远,请读者酌情考量,莫要浪费时间 ...

  10. SSL握手过程

    原文地址: http://my.oschina.net/u/1188877/blog/164982 一.SSL握手有三个目的:1. 客户端与服务器需要就一组用于保护数据的算法达成一致:2. 它们需要确 ...