# WA in HIT Problem(October Lunchtime 2019)

Can Anybody tell me why i got WA in this Problem.Following is the code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
int t;
cin>>t;
while(t–)
{
int n,a,cnt=0,flag=1,x=60,y=75,z=90;
cin>>n;
vectorh;
for(int i=0;i<n;i++)
{
cin>>a;
h.push_back(a);
}
sort(h.begin(),h.end());
for(int i=0;i<n;i++)
{
if(h[i]==h[i+1])cnt++;
else cnt=0;
if(cnt>(n/4)-1){flag=0;break;}
}
if(flag==0)cout<<"-1"<<endl;
else
{
x=h[n/4];
y=h[n/4+n/4];
z=h[n/4+n/4+n/4];
cout<<x<<" “<<y<<” "<<z<<endl;
}

``````}
return 0;
``````

}

Bro u have done count thing wrong…
Suppose array is
0 0 0 1 1 1 2 2 2 3 3 3
But answer is 1 2 3
What u should do is first sort…
Then compute x y z
Suppose u got values x from indexes h[n/4]
Compare it with h[n/4-1]
If they are equal it will be -1
Similar for y and z

1 Like

Thanks For Replying,But i Have a doubt.
For the Testcase : 0 0 0 1 1 1 2 2 2 3 3 3
My cnt will be 2
And answer will be 1 2 3
But i am not getting Why counting like this Wrong.

Sorry bro i missed something in your code…
First of all your loop is wrong as it is from 0 to n-1 and you are using index h[i+1]
Which you should avoid…
Take a test case
1 1 2 2 3 3 4 5 6 7 8 9

1 Like

Thank you @anon52292702 ,For the following test case : 1 1 2 2 3 3 4 5 6 7 8 9
My answer is 2 4 7 (Which is wrong)
I understood that concept of counting was wrong!
Thank you for the help!

Glad to see that u wr helped in any possible way out… When i saw it for first time i didn’t see that else statement…
So i gave u wrong test case…