CF1490F.Equalize the Array

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp was gifted an array aa of length nn. Polycarp considers an array beautiful if there exists a number CC, such that each number in the array occurs either zero or CC times. Polycarp wants to remove some elements from the array aa to make it beautiful.

For example, if n=6n=6 and a=[1,3,2,1,4,2]a = [1, 3, 2, 1, 4, 2], then the following options are possible to make the array aa array beautiful:

  • Polycarp removes elements at positions 22 and 55, array aa becomes equal to [1,2,1,2][1, 2, 1, 2];
  • Polycarp removes elements at positions 11 and 66, array aa becomes equal to [3,2,1,4][3, 2, 1, 4];
  • Polycarp removes elements at positions 1,21, 2 and 66, array aa becomes equal to [2,1,4][2, 1, 4];

Help Polycarp determine the minimum number of elements to remove from the array aa to make it beautiful.

Polycarp 收到了一个长度为 nn 的数组 aa。Polycarp 认为一个数组是“优美的”,当且仅当存在某个数 CC,使得该数组中每个数的出现次数要么为 00,要么恰好为 CC。Polycarp 希望从数组 aa 中删除一些元素,使其变为优美的数组。

例如,若 n=6n=6 且 a=[1,3,2,1,4,2]a = [1, 3, 2, 1, 4, 2],则以下几种删除方式可使数组 aa 变为优美的数组:

  • Polycarp 删除位置 22 和 55 上的元素,数组 aa 变为 [1,2,1,2][1, 2, 1, 2];
  • Polycarp 删除位置 11 和 66 上的元素,数组 aa 变为 [3,2,1,4][3, 2, 1, 4];
  • Polycarp 删除位置 1,21, 2 和 66 上的元素,数组 aa 变为 [2,1,4][2, 1, 4];

请帮助 Polycarp 确定:为使数组 aa 变为优美的数组,最少需要删除多少个元素。

输入格式

The first line 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 each test case consists of one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \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)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组 aa。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output one integer — the minimum number of elements that Polycarp has to remove from the array aa to make it beautiful.

对于每个测试用例,输出一个整数——Polycarp 需要从数组 aa 中删除的最少元素个数,以使其变得“美丽”。

输入输出样例

  • 输入#1

    3
    6
    1 3 2 1 4 2
    4
    100 100 4 100
    8
    1 2 3 3 3 2 6 6

    输出#1

    2
    1
    2

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

首页