CF1490F.Equalize the Array
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp was gifted an array a of length n. Polycarp considers an array beautiful if there exists a number C, such that each number in the array occurs either zero or C times. Polycarp wants to remove some elements from the array a to make it beautiful.
For example, if n=6 and a=[1,3,2,1,4,2], then the following options are possible to make the array a array beautiful:
- Polycarp removes elements at positions 2 and 5, array a becomes equal to [1,2,1,2];
- Polycarp removes elements at positions 1 and 6, array a becomes equal to [3,2,1,4];
- Polycarp removes elements at positions 1,2 and 6, array a becomes equal to [2,1,4];
Help Polycarp determine the minimum number of elements to remove from the array a to make it beautiful.
Polycarp 收到了一个长度为 n 的数组 a。Polycarp 认为一个数组是“优美的”,当且仅当存在某个数 C,使得该数组中每个数的出现次数要么为 0,要么恰好为 C。Polycarp 希望从数组 a 中删除一些元素,使其变为优美的数组。
例如,若 n=6 且 a=[1,3,2,1,4,2],则以下几种删除方式可使数组 a 变为优美的数组:
- Polycarp 删除位置 2 和 5 上的元素,数组 a 变为 [1,2,1,2];
- Polycarp 删除位置 1 和 6 上的元素,数组 a 变为 [3,2,1,4];
- Polycarp 删除位置 1,2 和 6 上的元素,数组 a 变为 [2,1,4];
请帮助 Polycarp 确定:为使数组 a 变为优美的数组,最少需要删除多少个元素。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.
The first line of each test case consists of one integer n (1≤n≤2⋅105) — the length of the array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — array a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 数组 a。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output one integer — the minimum number of elements that Polycarp has to remove from the array a to make it beautiful.
对于每个测试用例,输出一个整数——Polycarp 需要从数组 a 中删除的最少元素个数,以使其变得“美丽”。
输入输出样例
输入#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测评打分。不知道怎么写?