问题 C: Simple Set Problem

内存限制:256 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:2

题目描述

Given k non empty multiple sets, each multiple set only contains integers with absolute values not exceeding 10^9.

It is required to select exactly one number from each multiple set to form an array (a1,a2,,ak) with a length of k.

Assuming d=max(a1,a2,,ak)min(a1,a2,,ak).Please calculate the minimum d.

输入格式

Each test contains multiple test cases.The first line of input contains a single integer t(1t10^6)---the number of test cases.The description of test cases follows.

The first line of each test case contains a single integer k(1k10^6) —— the number of multiple sets.

The following k lines of each test case first read in a parameter ci —— indicating the size of the i-th multiple set, followed by ci integers with absolute values not exceeding 10^9 —— indicating the elements of the i-th multiple set.

Guarantee that i=1kci for each test case does not exceed 106106, the sum of i=1kci for all test cases does not exceed 4×10^6.

输出格式

For each testcase, output an integer representing the answer, which is the minimum d.

输入样例 复制

3
2
1 6
3 -7 7 10
4
9 -5 -9 2 8 5 4 3 3 8
2 10 8
1 -7
3 1 6 10
1
1 9

输出样例 复制

1
15
0