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 nn candies in a candy box. The type of the ii-th candy is aia_i (1≤ai≤n1 \le a_i \le 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 11 and two candies of type 22 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 qq independent queries.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

本题实际上是同一场比赛中问题 G 的一个子问题。

糖果盒中有 nn 颗糖果。第 ii 颗糖果的类型为 aia_i(1≤ai≤n1 \le a_i \le n)。

你需要用其中一部分糖果准备一份礼物,且需满足如下限制:礼物中每种类型的糖果数量必须互不相同(例如,礼物中包含 2 颗类型 1 的糖果和 2 颗类型 2 的糖果,这样的礼物是不合法的)。

礼物中可以完全不包含某些类型的糖果;对于某些类型,也可以只取其中的一部分糖果(而非全部)。

你的任务是:求出你能准备的单份礼物的最大可能大小(即糖果总数)。

你需要回答 qq 个相互独立的查询。

如果你使用 Python 编程,在提交代码时请考虑使用 PyPy 而非 Python。

输入格式

The first line of the input contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries. Each query is represented by two lines.

The first line of each query contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of candies.

The second line of each query contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n), where aia_i is the type of the ii-th candy in the box.

It is guaranteed that the sum of nn over all queries does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示查询次数。每次查询由两行组成。

每次查询的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示糖果的数量。

每次查询的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n),其中 aia_i 表示盒中第 ii 颗糖果的类型。

保证所有查询的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

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 88 and one candy of type 55, totalling to 33 candies.

Note that this is not the only possible solution — taking two candies of type 44 and one candy of type 66 is also valid.

在第一次查询中,你可以准备一份包含两颗类型为 88 的糖果和一颗类型为 55 的糖果的礼物,总共 33 颗糖果。

注意,这并非唯一的可行方案——选取两颗类型为 44 的糖果和一颗类型为 66 的糖果同样有效。

输入解题思路,AI测评打分。不知道怎么写?

首页