A16114 | Olya and Game with Arrays
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Artem suggested a game to the girl Olya. There is a list of $n$ arrays, where the $i$ -th array contains $m_i \ge 2$ positive integers $a_{i,1}, a_{i,2}, \ldots, a_{i,m_i}$ .
Olya 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 sum $\sum_{i=1}^n \min_{j=1}^{m_i} a_{i,j}$ . 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!
Olya 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 sum $\sum_{i=1}^n \min_{j=1}^{m_i} a_{i,j}$ . 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!
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 25000$ ) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 25000$ ) — 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 $m_i$ ( $2 \le m_i \le 50000$ ) — the number of elements in the $i$ -th array.
The next line contains $m_i$ integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, m_i}$ ( $1 \le a_{i,j} \le 10^9$ ) — the elements of the $i$ -th array.
It is guaranteed that the sum of $m_i$ over all test cases does not exceed $50000$ .
The first line of each test case contains a single integer $n$ ( $1 \le n \le 25000$ ) — 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 $m_i$ ( $2 \le m_i \le 50000$ ) — the number of elements in the $i$ -th array.
The next line contains $m_i$ integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, m_i}$ ( $1 \le a_{i,j} \le 10^9$ ) — the elements of the $i$ -th array.
It is guaranteed that the sum of $m_i$ over all test cases does not exceed $50000$ .
输出格式
For each test case, output a single line containing a single integer — the maximum beauty of the list of arrays that Olya can achieve.
输入输出样例
输入 #1
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
输出 #1
5 1 19
In the first test case, we can move the integer $3$ from the second array to the first array. Then the beauty is $\min(1, 2, 3) + \min(4) = 5$ . 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 $\min(100, 1, 6) = 1$ .
In the second test case, there is only one array, so regardless of the movements, the beauty will be $\min(100, 1, 6) = 1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted