Beautiful Regional Contest
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.
贪心题,先把最小的 g 取完,然后取最小的 s ,最后取最小的 d ,如果在这种情况下都(g+s+d)>n/2,
那么肯定不符合条件,如果符合条件的话然后在最大条件的制约下使 d 增大就行;
这里的一样的 p 要合在一起取;
#include<bits/stdc++.h>
#define LL long long
#define pa pair<int,int>
#define lson k<<1
#define rson k<<1|1
#define inf 0x3f3f3f3f
//ios::sync_with_stdio(false);
using namespace std;
const int N=100100;
const int M=4001000;
const LL mod=998244353;
int p[400100];
vector<int>ve;
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
ve.clear();
int n,g=0,s=0,b=0;
cin>>n;
for(int i=1;i<=n;i++) cin>>p[i];
p[n+1]=1e9;
int ans=1;
for(int i=1;i<=n;i++){
if(p[i]==p[i+1]) ans++;
else{
ve.push_back(ans);
ans=1;
}
}
g=ve[0];
for(int i=1;i<ve.size();i++){
s+=ve[i];
ans=i;
if(s>g) break;
}
for(int i=ans+1;i<ve.size();i++){
b+=ve[i];
ans=i;
if(b>g) break;
}
if(g+b+s>n/2){
cout<<0<<" "<<0<<" "<<0<<endl;
continue;
}
for(int i=ans+1;i<ve.size();i++){
b+=ve[i];
if(g+s+b>n/2){
b-=ve[i];
break;
}
}
cout<<g<<" "<<s<<" "<<b<<endl;
}
return 0;
}