CF1264A.Beautiful Regional Contest
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved pi problems. Since the participants are primarily sorted by the number of solved problems, then p1≥p2≥⋯≥pn.
Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied:
- for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0);
- the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b);
- each gold medalist must solve strictly more problems than any awarded with a silver medal;
- each silver medalist must solve strictly more problems than any awarded a bronze medal;
- each bronze medalist must solve strictly more problems than any participant not awarded a medal;
- the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants).
The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals.
因此,精彩的地区编程竞赛(BeRC)已圆满落幕!共有 n 名学生参加了本次竞赛。最终排名已经揭晓:排名第 i 位的选手解决了 pi 道题目。由于参赛者主要依据解题数量进行排序,因此有 p1≥p2≥⋯≥pn。
请协助裁判组分配金、银、铜牌。设金牌、银牌、铜牌的数量分别为 g、s 和 b。根据竞赛规则,以下所有条件均必须满足:
- 每种奖牌至少颁发一枚(即 g>0,s>0,且 b>0);
- 金牌数量必须严格少于银牌数量,也必须严格少于铜牌数量(即 g<s 且 g<b;但对 s 与 b 之间无大小要求);
- 每位金牌获得者解出的题目数必须严格多于任意一位银牌获得者;
- 每位银牌获得者解出的题目数必须严格多于任意一位铜牌获得者;
- 每位铜牌获得者解出的题目数必须严格多于任意一位未获奖牌的参赛者;
- 获奖总人数 g+s+b 不得超过全部参赛者人数的一半(例如,若 n=21,则最多可奖励 10 人;若 n=26,则最多可奖励 13 人)。
裁判组希望在满足上述所有条件的前提下,使获奖总人数最大化(即最大化 g+s+b)。请帮助裁判组找出一种满足条件的奖牌分配方案。
输入格式
The first line of the input contains an integer t (1≤t≤10000) — the number of test cases in the input. Then t test cases follow.
The first line of a test case contains an integer n (1≤n≤4⋅105) — the number of BeRC participants. The second line of a test case contains integers p1,p2,…,pn (0≤pi≤106), where pi is equal to the number of problems solved by the i-th participant from the final standings. The values pi are sorted in non-increasing order, i.e. p1≥p2≥⋯≥pn.
The sum of n over all test cases in the input does not exceed 4⋅105.
输入的第一行包含一个整数 t(1≤t≤10000),表示输入中测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤4⋅105),表示 BeRC 比赛的参赛人数。每个测试用例的第二行包含 n 个整数 p1,p2,…,pn(0≤pi≤106),其中 pi 表示最终排名中第 i 位参赛者所解决的问题数量。这些值 pi 按非递增顺序排列,即满足 p1≥p2≥⋯≥pn。
输入中所有测试用例的 n 值之和不超过 4⋅105。
输出格式
Print t lines, the j-th line should contain the answer to the j-th test case.
The answer consists of three non-negative integers g,s,b.
- Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time.
- Otherwise, print three positive numbers g,s,b — the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them.
输出 t 行,其中第 j 行应包含第 j 个测试用例的答案。
答案由三个非负整数 g,s,b 组成:
- 若不存在一种奖牌分配方案,使得题目陈述中的所有要求同时满足,则输出 g=s=b=0;
- 否则,输出三个正整数 g,s,b,分别表示金牌、银牌和铜牌的数量。要求 g+s+b 尽可能大;若存在多种满足条件的方案,输出任意一种即可。
输入输出样例
输入#1
5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11
输出#1
1 2 3 0 0 0 0 0 0 2 5 3 2 6 6
说明/提示
In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case.
In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
在第一个测试用例中,可以颁发 1 枚金牌、2 枚银牌和 3 枚铜牌。此时,解出 5 道题的参赛者将获得金牌,解出 4 道题的参赛者将获得银牌,解出 2 或 3 道题的参赛者将获得铜牌。恰好解出 1 道题的参赛者将不获得任何奖牌。容易看出,这种颁奖方式满足所有条件,因此是可行的。不可能颁发超过 6 枚奖牌,因为奖牌总数不得超过参赛人数的一半。答案 1、3、2 在该测试用例中同样正确。
在第二个和第三个测试用例中,无法颁发奖牌,因为每种类型的奖牌至少需颁发一枚,但奖牌总数又不得超过参赛人数的一半。
输入解题思路,AI测评打分。不知道怎么写?