CF1801C.Music Festival
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ki 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 ai,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.
男孩维佳非常喜欢听音乐。他知道本周五将发布 n 张专辑,其中第 i 张专辑包含 ki 首曲目。当然,维佳早已听过所有曲目,并且知道在第 i 张专辑中,第 j 首曲目的“酷度”为 ai,j。
维佳有个朋友玛莎,他非常希望邀请她一同参加音乐节,那里有他最喜欢的乐队演出。然而,玛莎要答应前往,必须先听完并评价这些新发布的专辑。维佳知道:如果玛莎听到一首曲目,其酷度严格高于之前听过的所有曲目,那么她就会获得 1 单位的“印象值”。不幸的是,专辑只能整张按顺序播放,不能打乱其中曲目的顺序。
请帮助维佳找出一种专辑的播放顺序,使得玛莎获得的印象值尽可能大,从而确保她一定会和他一起去音乐节。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤200000) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1≤n≤200000) — number of albums.
The album descriptions follow. Each album description consists of two lines:
The first line contains a single integer ki (1≤ki≤200000) — the number of tracks in the ith album.
The following line contains ki integers ai,1, ai,2, ai,3, …, ai,ki (1≤ai,j≤200000) — the coolness of the tracks in the i album.
Denote for ∑ki the sum of all ki. It is guaranteed that ∑ki≤200000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤200000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤200000),表示专辑数量。
接下来是专辑的描述。每个专辑的描述由两行组成:
第一行包含一个整数 ki(1≤ki≤200000),表示第 i 张专辑中的曲目数量。
下一行包含 ki 个整数 ai,1, ai,2, ai,3, …, ai,ki(1≤ai,j≤200000),表示第 i 张专辑中各曲目的酷炫值。
记 ∑ki 为所有 ki 的总和。保证 ∑ki≤200000。
输出格式
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.
在第一个测试样例中,最优的收听顺序是:第 4 张、第 2 张、第 3 张和第 1 张专辑。
此时,玛莎将按如下顺序收听歌曲:1;7;8, 6;4, 9, 4, 6, 8,并获得 4 单位的印象值。
在第二个测试样例中,必须首先收听第 1 张专辑,然后是第 4 张专辑,而第 2 张和第 3 张专辑则可以以任意顺序收听。此时,玛莎将获得最大印象值,且第 1 张和第 4 张专辑中的每首歌曲均贡献印象值,而第 2 张和第 3 张专辑则不贡献任何印象值。
输入解题思路,AI测评打分。不知道怎么写?