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. [转]Erlang不能错过的盛宴

    Erlang不能错过的盛宴 (快步进入Erlang的世界) 作者:成立涛 (litaocheng@gmail.com) 作为程序员,我们曾经闻听很多“业界动态”,“技术革新”,曾经接触很多“高手箴言” ...

  2. Static块详解

    首先,我们先看一段程序,代码如下: public class Father { public Father() //构造方法 { System.out.println(" 父类构造方法&qu ...

  3. homework -06 围棋

    playPrev功能的实现 public void playPrev(ref GoMove gm) { Point p = gm.Point; m_colorToPlay = gm.Color; cl ...

  4. 获取iOS设备信息(内存/电量/容量/型号/IP地址/当前WIFI名称)

    1.获取电池电量(一般用百分数表示,大家自行处理就好) 1 2 3 4 -(CGFloat)getBatteryQuantity {         return [[UIDevice current ...

  5. 在Delphi7中JSON遍历节点不支持使用IN处理方法

    相关资料:http://www.cnblogs.com/del/archive/2009/10/23/1588690.html Delphi2007源代码: procedure TForm1.Butt ...

  6. ocp 1Z0-051 71-105题解析

    71. Which arithmeticoperations can be performed on a column by using a SQL function that is builtint ...

  7. iOS 将图片保存到本地

    //将图片保存到本地 + (void)SaveImageToLocal:(UIImage*)image Keys:(NSString*)key {     NSUserDefaults* prefer ...

  8. 一个简单的Socket通信Demo

    服务器端Demo: Server.java(服务器端运行主程序,直接运行): package cn.wjs; import java.net.InetAddress; import java.net. ...

  9. iOS开发代码规范

    1.关于命名 1.1统一要求 含义清楚, 尽量做到不需要注释也能了解其作用,若做不到,就加注释 使用全称不使用缩写 1.2类的命名 大驼峰式命名:每一个单词的首字母都采用大写字母例子: MFHomeP ...

  10. MyBatis中井号与美元符号的区别

    #{变量名}可以进行预编译.类型匹配等操作,#{变量名}会转化为jdbc的类型. select * from tablename where id = #{id} 假设id的值为12,其中如果数据库字 ...