CF1335C.Two Teams Composing

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have nn students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the ii-th student skill is denoted by an integer aia_i (different students can have the same skills).

So, about the teams. Firstly, these two teams should have the same size. Two more constraints:

  • The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).
  • The second team should consist of students with the same skills (i.e. all skills in the second team are equal).

Note that it is permissible that some student of the first team has the same skill as a student of the second team.

Consider some examples (skills are given):

  • [1,2,3][1, 2, 3], [4,4][4, 4] is not a good pair of teams because sizes should be the same;
  • [1,1,2][1, 1, 2], [3,3,3][3, 3, 3] is not a good pair of teams because the first team should not contain students with the same skills;
  • [1,2,3][1, 2, 3], [3,4,4][3, 4, 4] is not a good pair of teams because the second team should contain students with the same skills;
  • [1,2,3][1, 2, 3], [3,3,3][3, 3, 3] is a good pair of teams;
  • [5][5], [6][6] is a good pair of teams.

Your task is to find the maximum possible size xx for which it is possible to compose a valid pair of teams, where each team size is xx (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.

You have to answer tt independent test cases.

你手下有 nn 名学生,需要恰好组成两个队伍,每个队伍由其中一部分学生构成。每名学生都有自己的技能值,第 ii 名学生的技能值用整数 aia_i 表示(不同学生可以具有相同的技能值)。

关于这两个队伍,需满足以下条件:
首先,这两个队伍必须具有相同的大小。此外还有两条约束:

  • 第一个队伍中的学生技能值必须互不相同(即第一个队伍中所有技能值均唯一);
  • 第二个队伍中的学生技能值必须完全相同(即第二个队伍中所有技能值都相等)。

注意:第一个队伍中某学生的技能值与第二个队伍中某学生的技能值可以相同。

考虑如下一些例子(括号内为技能值列表):

  • [1,2,3][1, 2, 3], [4,4][4, 4] 不是一组合法的队伍,因为两支队伍大小不相等;
  • [1,1,2][1, 1, 2], [3,3,3][3, 3, 3] 不是一组合法的队伍,因为第一个队伍中存在技能值重复的学生;
  • [1,2,3][1, 2, 3], [3,4,4][3, 4, 4] 不是一组合法的队伍,因为第二个队伍中技能值不全相同;
  • [1,2,3][1, 2, 3], [3,3,3][3, 3, 3] 是一组合法的队伍;
  • [5][5], [6][6] 是一组合法的队伍。

你的任务是找出最大的可能的队伍大小 xx,使得能够组成一组合法的队伍,其中每个队伍大小均为 xx(第一个队伍中技能值互不相同,第二个队伍中技能值全部相同)。每名学生至多只能属于一个队伍。

你需要处理 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of students. The second line of the test case 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 skill of the ii-th student. Different students can have the same skills.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5 (∑n≤2⋅105\sum n \le 2 \cdot 10^5).

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 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(即 ∑n≤2⋅105\sum n \le 2 \cdot 10^5)。

输出格式

For each test case, print the answer — the maximum possible size xx for which it is possible to compose a valid pair of teams, where each team size is xx.

对于每个测试用例,输出答案——即能够组成一对有效队伍时,每支队伍的最大可能大小 xx。

输入输出样例

  • 输入#1

    4
    7
    4 2 4 1 4 3 4
    5
    2 1 5 4 3
    1
    1
    4
    1 1 1 3

    输出#1

    3
    1
    0
    2

说明/提示

In the first test case of the example, it is possible to construct two teams of size 33: the first team is [1,2,4][1, 2, 4] and the second team is [4,4,4][4, 4, 4]. Note, that there are some other ways to construct two valid teams of size 33.

在示例的第一个测试用例中,可以构造两个大小为 33 的队伍:第一支队伍为 [1,2,4][1, 2, 4],第二支队伍为 [4,4,4][4, 4, 4]。注意,还存在其他多种方式来构造两个合法的、大小为 33 的队伍。

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

首页