CF1183D.Candy Box (easy version)
普及/提高-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This problem is actually a subproblem of problem G from the same contest.
There are n candies in a candy box. The type of the i-th candy is ai (1≤ai≤n).
You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad).
It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.
Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.
You have to answer q independent queries.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
本题实际上是同一场比赛中问题 G 的一个子问题。
糖果盒中有 n 颗糖果。第 i 颗糖果的类型为 ai(1≤ai≤n)。
你需要用其中一部分糖果准备一份礼物,且需满足如下限制:礼物中每种类型的糖果数量必须互不相同(例如,礼物中包含 2 颗类型 1 的糖果和 2 颗类型 2 的糖果,这样的礼物是不合法的)。
礼物中可以完全不包含某些类型的糖果;对于某些类型,也可以只取其中的一部分糖果(而非全部)。
你的任务是:求出你能准备的单份礼物的最大可能大小(即糖果总数)。
你需要回答 q 个相互独立的查询。
如果你使用 Python 编程,在提交代码时请考虑使用 PyPy 而非 Python。
输入格式
The first line of the input contains one integer q (1≤q≤2⋅105) — the number of queries. Each query is represented by two lines.
The first line of each query contains one integer n (1≤n≤2⋅105) — the number of candies.
The second line of each query contains n integers a1,a2,…,an (1≤ai≤n), where ai is the type of the i-th candy in the box.
It is guaranteed that the sum of n over all queries does not exceed 2⋅105.
输入的第一行包含一个整数 q(1≤q≤2⋅105),表示查询次数。每次查询由两行组成。
每次查询的第一行包含一个整数 n(1≤n≤2⋅105),表示糖果的数量。
每次查询的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n),其中 ai 表示盒中第 i 颗糖果的类型。
保证所有查询的 n 值之和不超过 2⋅105。
输出格式
For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.
对于每个查询,输出一个整数——在本查询所获得的糖果中,按照题目描述的限制条件所能组成的单个礼物的最大可能大小。
输入输出样例
输入#1
3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7
输出#1
3 10 9
说明/提示
In the first query, you can prepare a gift with two candies of type 8 and one candy of type 5, totalling to 3 candies.
Note that this is not the only possible solution — taking two candies of type 4 and one candy of type 6 is also valid.
在第一次查询中,你可以准备一份包含两颗类型为 8 的糖果和一颗类型为 5 的糖果的礼物,总共 3 颗糖果。
注意,这并非唯一的可行方案——选取两颗类型为 4 的糖果和一颗类型为 6 的糖果同样有效。
输入解题思路,AI测评打分。不知道怎么写?