A15838 | Music Festival
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The boy Vitya loves to listen to music very much. He knows that $n$ albums are due to be released this Friday, $i$ -th of which contains $k_i$ tracks. Of course, Vitya has already listened to all the tracks, and knows that in the $i$ -th album, the coolness of the $j$ -th track is equal to $a_{i,j}$ .Vitya has a friend Masha, whom he really wants to invite to the festival, where his favorite bands perform. However, in order for a friend to agree, she must first evaluate the released novelties. Vitya knows that if Masha listens to a track that was cooler than all the previous ones, she will get 1 unit of impression. Unfortunately, albums can only be listened to in their entirety, without changing the songs in them in places.
Help Vitya find such an order of albums so that Masha's impression turns out to be as much as possible, and she definitely went to the festival with him.
Help Vitya find such an order of albums so that Masha's impression turns out to be as much as possible, and she definitely went to the festival with him.
输入格式
Each test consists of multiple test cases. The first line contains a single integer t ( $1 \le t \le 200\,000$ ) — 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 200\,000$ ) — number of albums.
The album descriptions follow. Each album description consists of two lines:
The first line contains a single integer $k_i$ ( $1 \le k_i \le 200\,000$ ) — the number of tracks in the $i$ th album.
The following line contains $k_i$ integers $a_{i, 1},\ a_{i, 2},\ a_{i, 3},\ \ldots,\ a_{i, k_i}$ ( $1 \le a_{i,j} \le 200\,000$ ) — the coolness of the tracks in the $i$ album.
Denote for $\sum k_i$ the sum of all $k_i$ . It is guaranteed that $\sum k_i \le 200\,000$ .
The first line of each test case contains a single integer $n$ ( $1 \le n \le 200\,000$ ) — number of albums.
The album descriptions follow. Each album description consists of two lines:
The first line contains a single integer $k_i$ ( $1 \le k_i \le 200\,000$ ) — the number of tracks in the $i$ th album.
The following line contains $k_i$ integers $a_{i, 1},\ a_{i, 2},\ a_{i, 3},\ \ldots,\ a_{i, k_i}$ ( $1 \le a_{i,j} \le 200\,000$ ) — the coolness of the tracks in the $i$ album.
Denote for $\sum k_i$ the sum of all $k_i$ . It is guaranteed that $\sum k_i \le 200\,000$ .
输出格式
For each test case print the singular number — the maximum impression that Masha can get.
输入输出样例
输入 #1
2 4 5 4 9 4 6 8 1 7 2 8 6 1 1 4 2 3 4 2 1 8 2 2 8 2 7 9
输出 #1
4 4
In the first test example, the optimal order is listening to the 4th, 2nd, 3rd and 1st albums.
In this case, Masha will listen to the tracks in the following order: 1; 7; 8, 6; 4, 9, 4, 6, 8 and will receive 4 units of impression.
In the second test example, you must first listen to the 1st, then the 4th, and in any order the 2nd and 3rd. In this case, Masha will get the maximum impression, and for every song in the 1st and 4th albums and nothing for the 2nd and 3rd.
In this case, Masha will listen to the tracks in the following order: 1; 7; 8, 6; 4, 9, 4, 6, 8 and will receive 4 units of impression.
In the second test example, you must first listen to the 1st, then the 4th, and in any order the 2nd and 3rd. In this case, Masha will get the maximum impression, and for every song in the 1st and 4th albums and nothing for the 2nd and 3rd.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted