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

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.


解题思路
题目有多种答案,输出一种符合要求的就OK,所以首先找出金牌的数目,然后以金牌的数目为基础,计算银牌的数量,(银牌 > 金牌)剩下的(len / 2)都给铜牌。如果最终在限定的范围内,没有达到要求,则输出0 0 0 ,否则输出 3种牌子的数目。

代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

int ans[1000005];  // 存入数值
int res[1000005];  //存入不同的数值


int main(){
    SIS;
    int t;
    cin>>t;
    while(t--){
        int n;
        int g = 0, b = 0,s = 0;
        cin>>n;
        for (int i = 0; i < n; i++){
            cin>>ans[i];
        }
        int len = n / 2; // 牌子的数目
        int cnt = 0;
        if (len >= 3){  // 如果还没有4个,则输出0 0 0  n为7时,n/2 为 3,所以这里 >=3
            int i ;
            map <int , int> St; // 存入不同数值的数目
            res[cnt++] =  ans[0];
            St[ans[0]] ++;
            for (i = 1; i < len ; i++){
                if (ans[i] != ans[i - 1]){
                    res[cnt++] = ans[i];  // res 存不同的数
                }
                St[ans[i]] ++; // 每个数的有多少
            }
            while( i < n && ans[i] == ans[i - 1]){ // 最后相同的也要加在铜牌里
                St[ans[i]] ++;
                i ++;
            }
            g = St[ans[0]];  // 金的个数
            for (i = 1; i < cnt && g >= s; i++){  //银的个数
                s += St[res[i]];
            }
            for (; i < cnt; i++){  // 铜的个数
                b += St[res[i]];
            }
            int x = cnt;
            while(g + s + b > len){  // 个数超范围,适当的缩减
                 b -= St[res[--x]];
            }
            if (g > 0 && s > 0 && g < b) {
                printf("%d %d %d\n",g,s,b);
            }
            else{
                printf("0 0 0\n");
            }
        }
        else{
            printf("0 0 0\n");
        }
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值