4600: Games
题目描述
Bob suggested a game to the girl Alice. There is a list of n arrays, where the i-th array contains mi≥2 positive integers ai,1,ai,2,…,ai,mi
Alice can move at most one (possibly 0) integer from each array to another array. Note that integers can be moved from one array only once, but integers can be added to one array multiple times, and all the movements are done at the same time.The beauty of the list of arrays is defined as the sumIn other words, for each array, we find the minimum value in it and then sum up these values.
The goal of the game is to maximize the beauty of the list of arrays. Help Alice win this challenging game!
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤25000) — the number of test cases. The desc
The first line of each test case contains a single integer n (1≤n≤25000) — the number of arrays in the list.
This is followed by desc
The first line contains a single integer mi (2≤mi≤50000) — the number of elements in the i-th array.
The next line contains mi integers ai,1,ai,2,…,ai,mi(1≤ai,j≤109) — the elements of the i-th array.
It is guaranteed that the sum of mi over all test cases does not exceed 50000.
输出格式
输入样例 复制
3
2
2
1 2
2
4 3
1
3
100 1 6
3
4
1001 7 1007 5
3
8 11 6
2
2 9
输出样例 复制
5
1
19