Description:
\quad 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.
\quad 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 g>0, s>0 g>0,s>0 and b > 0 b>0 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 g<s g<s and g < b g<b g<b, but there are
no requirements between s s s and b b 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
g+s+b
g+s+b should not exceed half of all
participants (for example, if n = 21 n=21 n=21, then you can award a maximum of
10 10 10 participants, and if n = 26 n=26 n=26, then you can award a maximum of 13 13 13
participants).
\quad The jury wants to reward with medals the total maximal number participants ( i . e i.e i.e. to maximize g + s + b g+s+b g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals.
Input
\quad The first line of the input contains an integer t ( 1 ≤ t ≤ 10000 ) t (1≤t≤10000) t(1≤t≤10000)— the number of test cases in the input. Then t t t test cases follow.
\quad The first line of a test case contains an integer n ( 1 ≤ n ≤ 4 ⋅ 1 0 5 ) n (1≤n≤4⋅10^5) n(1≤n≤4⋅105) — the number of BeRC participants. The second line of a test case contains integers p 1 , p 2 , … , p n ( 0 ≤ p i ≤ 1 0 6 ) p_{1},p_{2},…,p_{n} (0≤p_{i}≤10^6) 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 . p 1 ≥ p 2 ≥ ⋯ ≥ p n . i.e. p_{1}≥p_{2}≥⋯≥p_{n}. 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 . g,s,b. g,s,b.
\quad
Print
g
=
s
=
b
=
0
g=s=b=0
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
g,s,b
g,s,b — the possible number of gold, silver and bronze medals, respectively. The sum of
g
+
s
+
b
g+s+b
g+s+b should be the maximum possible. If there are several answers, print any of them.
Example
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
output
1 2 3
0 0 0
0 0 0
2 5 3
2 6 6
Note
\quad In the first test case, it is possible to reward 1 1 1 gold, 2 2 2 silver and 3 3 3 bronze medals. In this case, the participant solved 5 5 5 tasks will be rewarded with the gold medal, participants solved 4 4 4 tasks will be rewarded with silver medals, participants solved 2 2 2 or 3 3 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 1 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 6 6 medals because the number of medals should not exceed half of the number of participants. The answer 1 , 3 , 2 1, 3, 2 1,3,2 is also correct in this test case.
\quad
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.
**题意:**分金银铜牌 规则是获得金牌的人题数严格大于得银牌的 银牌的严格大于铜牌的 金牌数严格小于银牌数和铜牌数 三个牌子的总和不多于总人数的一半 给定人数和过题数 希望牌子尽量多 输出方案
贪心 金牌只取最多过题数的人数 银牌取到比金牌多就break 铜剩下 判是否符合要求
AC代码:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
int ret = 0, sgn = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ret = ret*10 + ch - '0';
ch = getchar();
}
return ret*sgn;
}
inline void Out(int a) //Êä³öÍâ¹Ò
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
ll gcd(ll a,ll b)
{
return b==0?a : gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
///快速幂m^k%mod
int qpow(int m, int k, int mod)
{
int res = 1, t = m;
while (k)
{
if (k&1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
// 快速幂求逆元
int Fermat(int a, int p) //费马求a关于b的逆元
{
return qpow(a,p-2,p);
}
///扩展欧几里得
int exgcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
int g=exgcd(b,a%b,x,y);
int t=x;
x=y;
y=t-a/b*y;
return g;
}
///使用ecgcd求a的逆元x
int mod_reverse(int a,int p)
{
int d,x,y;
d=exgcd(a,p,x,y);
if(d==1)
return (x%p+p)%p;
else
return -1;
}
///中国剩余定理模板
ll china(int a[],int b[],int n)//a[]为除数,b[]为余数
{
int M=1,y,x=0;
for(int i=0; i<n; ++i) //算出它们累乘的结果
M*=a[i];
for(int i=0; i<n; ++i)
{
int w=M/a[i];
int tx=0;
int t=exgcd(w,a[i],tx,y);//计算逆元
x=(x+w*(b[i]/t)*x)%M;
}
return (x+M)%M;
}
int n,m;
int i,j,k;
int t;
int res,temp,cnt,num;
int ans,pos;
const int MAX_N=4e5+5;
int a[MAX_N];
int main()
{
int T;
sd(T);
while(T--)
{
sd(n);
rep(i,1,n)
sd(a[i]);
int pos=2;
int g=1;
for(; pos<=n/2; pos++)
{
if(a[pos]!=a[pos-1])
break;
g++;
}
if(pos>n/2)
{
printf("0 0 0\n");
continue;
}
pos++;
int s=1;
for(; pos<=n/2; pos++)
{
if(s>g&&a[pos]!=a[pos-1])
break;
s++;
}
int pos2;
for(pos2=n/2;; pos2--)
if(a[pos2]!=a[pos2+1])
break;
int b=pos2-pos+1;
if(b>g&&s>g)
printf("%d %d %d\n",g,s,b);
else
printf("0 0 0\n");
}
return 0;
}