欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1859B.Olya and Game with Arrays
Olya and Game with Arrays
Artem suggested a game to the girl Olya. There is a list of arrays, where the -th array contains positive integers .
Olya can move at most one (possibly ) 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 sum . In 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 Olya win this challenging game!
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () — the number of arrays in the list.
This is followed by descriptions of the arrays. Each array description consists of two lines.
The first line contains a single integer () — the number of elements in the -th array.
The next line contains integers () — the elements of the -th array.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single line containing a single integer — the maximum beauty of the list of arrays that Olya can achieve.
Note
In the first test case, we can move the integer from the second array to the first array. Then the beauty is . It can be shown that this is the maximum possible beauty.
In the second test case, there is only one array, so regardless of the movements, the beauty will be .
Samples
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
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |