【CodeForces 1265C --- Beautiful Regional Contest】

题目来源:点击进入【CodeForces 1265C — Beautiful Regional Contest】

Description

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.

Input

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.

Output

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.

Sample Input

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

Sample Output

1 2 3
0 0 0
0 0 0
2 5 3
2 6 6

Note

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.

解题思路:

题上并没有要求尽量尽量金牌,银牌多,所以我们只需将最大的那种为金牌,其次的为银牌,剩下的都是铜牌,最后判断是否符合要求就行。

AC代码1:

#include <bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
const int MAXN = 4e5+5;
int arr[MAXN],num[MAXN];int main()
{SIS;int T,n;cin >> T;while(T--){int g=0,s=0,b=0;cin >> n;for(int i=0;i<n;i++) cin >> arr[i];int len=n/2,cnt=0;if(len>=3){int i;num[cnt++]=arr[0];map<int,int> m;m[arr[0]]++;for(i=1;i<len;i++){if(arr[i]!=arr[i-1])num[cnt++]=arr[i];m[arr[i]]++;}while(i<n && arr[i]==arr[i-1]) m[arr[i]]++,i++;g=m[num[0]];for(i=1;i<cnt && s<=g;i++) s+=m[num[i]];for(;i<cnt;i++) b+=m[num[i]];int x=cnt;while(g+s+b>len) b-=m[num[--x]];if(g>0 && s>0 && g<b) cout << g << " " << s << " " << b << endl;else cout << "0 0 0" << endl;}else cout << "0 0 0" << endl;}return 0;
}

【CodeForces 1265C --- Beautiful Regional Contest】相关推荐

  1. 【Codeforces Round #767 (Div. 2)】 C. Meximum Array 题解

    [Codeforces Round #767 (Div. 2) ]C. Meximum Array 题解 1629C: Meximum Array 题解 [Codeforces Round #767 ...

  2. C. Beautiful Regional Contest

    链接:https://codeforces.com/contest/1265/problem/C So the Beautiful Regional Contest (BeRC) has come t ...

  3. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    [题目链接]C题链接 [题目类型]思维.模拟 [题目大意]一共有t个测试样例.一共有n个人进行答题,每个人分别答出a[i]个题,现在要求你为这个比赛设计奖项,分别有金牌.银牌.铜牌.没有奖牌四个选项. ...

  4. 【Codeforces Round #548(Div. 2)】Edgy Trees(数学+bfs求连通块)

    题目链接 C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 【Codeforces Round #525(Div. 2)】Ehab and another another xor problem(思维+异或)

    题目链接 D. Ehab and another another xor problem time limit per test 1 second memory limit per test 256 ...

  6. 【Codeforces Round#618 (Div. 2)】C. Anu Has a Function 题解

    题目链接:C. Anu Has a Function 题目 Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the ...

  7. C1. Make Nonzero Sum (easy version)【Codeforces Round #829 (Div. 2】

    Codeforces Round #829 (Div. 2)中C1题目 Codeforces比赛记录 文章目录 题目链接: 一.C1. Make Nonzero Sum (easy version) ...

  8. 【Codeforces Round #784 (Div. 4)】【AK题解】

    2022年4月30日19:43:21 文章目录 2022年4月30日19:43:21 A. Division? 题目描述 测试样例 题解 B. Triple 题目描述 测试样例 题解 C. Odd/E ...

  9. 【Codeforces Round #560 (Div. 3)】 A B C D E F1 F2

    cf560 A 题意 给你一个 2e5的01串 和 x y要求这个串%10^x = 10 ^ y 那么按照题意模拟 都变成0 那位变成1 即可 /*if you can't see the repay ...

最新文章

  1. ios uiview 如何刷新_UIView的重绘及布局刷新
  2. runtime运行时编程一些相关知识
  3. Nmap扫描教程之网络基础服务DHCP服务类
  4. [Python]小甲鱼Python视频第003课(插曲之变量和字符串)课后题及参考解答
  5. SpringBoot继承LogStash实现日志收集
  6. 如何解决ado.net entity framework的使用,再别的调用项目中依然正常
  7. 安卓application_安卓系统蓝牙配对流程分析
  8. java bcd码_java中BCD编码
  9. Linux用户管理(六)Linux磁盘管理
  10. WMI 错误 10的解决
  11. android端使用mockServer
  12. Windows使用Dism备份操作系统快捷命令 系统备份
  13. 一学就会的 WordPress 实战课
  14. 14----统计字符数
  15. i = i++, i = ++i, j = i++, j = ++i 的区别
  16. java改成字体_更改JRE字体配置
  17. .dll、.lib、.a的转换
  18. ajax分页 2017,ajax分页
  19. Spring框架+SPringleMVC-狂神版整理
  20. 实时数据库:一夜之间,我感受到了时序数据库的威胁

热门文章

  1. 《隐秘的角落》影评数据分析
  2. 轻应用:发票小助手开发示例(Vue + Amaze UI + OkayApi)
  3. 跟着团子学SAP PS:项目报价解决方案(上)
  4. 页面自适应各种手机屏幕:阿赛特别方法处理页面固定宽度适应各种终端的解决方案
  5. 利用Gitee搭建私人仓库-https篇
  6. 使用proces explorer查看系统gdi
  7. 【新闻】天洑软件参展第五届智能优化与调度学术会议
  8. 网络改造--光猫更换升级
  9. PMBOK(第六版)第一章 引论
  10. PMP项目管理实战 | 项目经理如何做好会议管理?