CF1626D.Martial Arts Tournament
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp is planning to host a martial arts tournament. There will be three divisions based on weight: lightweight, middleweight and heavyweight. The winner of each division will be determined by a single elimination system.
In particular, that implies that the number of participants in each division should be a power of two. Additionally, each division should have a non-zero amount of participants.
n participants have registered for the tournament so far, the i-th of them weighs ai. To split participants into divisions, Monocarp is going to establish two integer weight boundaries x and y (x<y).
All participants who weigh strictly less than x will be considered lightweight. All participants who weigh greater or equal to y will be considered heavyweight. The remaining participants will be considered middleweight.
It's possible that the distribution doesn't make the number of participants in each division a power of two. It can also lead to empty divisions. To fix the issues, Monocarp can invite an arbitrary number of participants to each division.
Note that Monocarp can't kick out any of the n participants who have already registered for the tournament.
However, he wants to invite as little extra participants as possible. Help Monocarp to choose x and y in such a way that the total amount of extra participants required is as small as possible. Output that amount.
莫诺卡普计划举办一场武术锦标赛。比赛将根据体重分为三个级别:轻量级、中量级和重量级。每个级别的冠军将通过单败淘汰制决出。
特别地,这意味着每个级别中的参赛人数必须是 2 的幂次。此外,每个级别都必须至少有 1 名参赛者。
目前已有 $ n $ 名参赛者报名,其中第 $ i $ 名参赛者的体重为 $ a_i $。为了将参赛者分配至各级别,莫诺卡普将设定两个整数体重分界值 $ x $ 和 $ y $(满足 $ x < y $):
- 所有体重严格小于 $ x $ 的参赛者被划入轻量级;
- 所有体重大于等于 $ y $ 的参赛者被划入重量级;
- 其余参赛者被划入中量级。
这种划分方式可能导致某个级别的参赛人数不是 2 的幂次,也可能导致某些级别无人参赛。为解决这些问题,莫诺卡普可以向每个级别任意邀请额外的参赛者。
注意:莫诺卡普不能将已报名的 $ n $ 名参赛者中的任何一人剔除。
但他希望邀请的额外参赛者总数尽可能少。请帮助莫诺卡普选择合适的 $ x $ 和 $ y $,使得所需额外参赛者总数最小,并输出该最小总数。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
The first line of each testcase contains a single integer n (1≤n≤2⋅105) — the number of the registered participants.
The second line of each testcase contains n integers a1,a2,…,an (1≤ai≤n) — the weights of the registered participants.
The sum of n over all testcases doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 注册参赛者的数量。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 注册参赛者的体重。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each testcase, print a single integer — the smallest number of extra participants Monocarp is required to invite after he chooses the weight boundaries x and y.
对于每个测试用例,输出一个整数——即在蒙诺卡普选定重量边界 x 和 y 后,他需要额外邀请的最少参与者人数。
输入输出样例
输入#1
4 4 3 1 2 1 1 1 6 2 2 2 1 1 1 8 6 3 6 3 6 3 6 6
输出#1
0 2 3 2
说明/提示
In the first testcase of the example, Monocarp can choose x=2 and y=3. Lightweight, middleweight and heavyweight divisions will have 2, 1 and 1 participants, respectively. They all are powers of two, so no extra participants are required.
In the second testcase of the example, regardless of the choice of x and y, one division will have 1 participant, the rest will have 0. Thus, Monocarp will have to invite 1 participant into both of the remaining divisions.
In the third testcase of the example, Monocarp can choose x=1 and y=2. Lightweight, middleweight and heavyweight divisions will have 0, 3 and 3 participants, respectively. So an extra participant is needed in each division.
In the fourth testcase of the example, Monocarp can choose x=8 and y=9. Lightweight, middleweight and heavyweight divisions will have 8, 0 and 0 participants, respectively. Middleweight and heavyweight division need an extra participant each.
在示例的第一个测试用例中,Monocarp 可以选择 x=2 和 y=3。轻量级、中量级和重量级三个组别将分别有 2、1 和 1 名参赛者。这些人数均为 2 的幂,因此无需额外邀请参赛者。
在示例的第二个测试用例中,无论 x 和 y 如何选择,总有一个组别有 1 名参赛者,其余两个组别各有 0 名参赛者。因此,Monocarp 需要向其余两个组别各邀请 1 名参赛者。
在示例的第三个测试用例中,Monocarp 可以选择 x=1 和 y=2。轻量级、中量级和重量级三个组别将分别有 0、3 和 3 名参赛者。因此,每个组别都需要额外增加 1 名参赛者。
在示例的第四个测试用例中,Monocarp 可以选择 x=8 和 y=9。轻量级、中量级和重量级三个组别将分别有 8、0 和 0 名参赛者。中量级和重量级组别各需额外增加 1 名参赛者。
输入解题思路,AI测评打分。不知道怎么写?