# HIT Editorial

Tester: Teja Reddy

### PROBLEM EXPLANATION

Given the grades of 4*N students in the form of an array A[1\ldots4*N]. Set the boundaries for each letter grade (A,B,C,D) such that the number of students having any letter is exactly N.
You need to find x,y,z such that if:
0 \leq score \lt x means that grade is D
x \leq score \lt y means that grade is C
y \leq score \lt z means that grade is B
z \leq score \lt 100 means that grade is A
Find a solution that maximizes x+y+z or state that there’s no solution.

Cakewalk

None

### EXPLANATION:

Sort the students grades A[1 \ldots 4*N] according to their grades in ascending order.
The first N students should get D specifically students corresponding to grades A[1 \ldots N]
The next N students should get C specifically students corresponding to grades A[N+1 \ldots 2*N]
The next N students should get B specifically students corresponding to grades A[2*N+1 \ldots 3*N]
The next N students should get A specifically students corresponding to grades A[3*N+1 \ldots 4*N]

Formally speaking:
x=A_{N+1}
y=A_{2*N+1}
z=A_{3*N+1}

When we don’t have a solution? In any case that satisfies:
(A_{N+1}=A_N) OR (A_{2*N+1}=A_{2*N}) OR (A_{3*N+1}=A_{3*N})

Because the grades won’t be consistent with the boundaries.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
using namespace std;
int T , n , arr[200];
int main(){
cin>>T;
while(T--) {
cin >> n;
for (int j = 0; j < n; j++) {
cin >> arr[j];
}
sort(arr , arr + n);
int a = n/4 , b = a + a , c = a + a + a;
if (arr[a] == arr[a-1] || arr[b] == arr[b-1] || arr[c] == arr[c-1]) puts("-1");
else cout << arr[a] << ' ' << arr[b] << ' ' << arr[c] << endl;
}
return 0;
}


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;


}

if(h[i]==h[i+1])cnt++; and if(cnt>(n/4)-1){flag=0;break;} are acting as a and statement, i.e., if all the 3 h[i]==h[i+1] are true only then it will give -1 as the answer, however it should have been such that if any of the h[i]==h[i+1] is true, flag would be false

Any Python programmers here. ?
I attempted this problem with the following code: https://www.codechef.com/viewsolution/27648021

Can someone point out some issues or something that’s not handled?

please can anyone help why i got wrong answer in the following code-:

#include
using namespace std;

int main()
{
int T;
cin>>T;
int in=0;
while(in!=T)
{
int te=0;
int N;
cin>>N;
int a[N];
for(int i=0;i<N;i++)
{
cin>>a[i];

}
int x=60,y=75,z=90,D=0,C=0,B=0,A=0;
for(int i=0;i<N;i++)
{
if(a[i]<x)
D++;
else if(a[i]>=x&&a[i]<y)
C++;
else if(a[i]>=y&&a[i]<z)
B++;
else
A++;
}

for(int i=N-1;i>=1;i--)
{
for(int j=0;j<=i-1;j++)
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}

for(int i=0;i<N-1;i++)
{
if(a[i]==a[i+1])
{
cout<<"-1";
cout<<endl;
te=7;
break;

}

}

if(A==B&&B==C&&C==D&&te!=7)
cout<<x<<" "<<y<<" "<<z<<endl;
else if(te!=7)
{

A=N/4;
B=N/4;
C=N/4;
D=N/4;
x=a[A-1+1];
y=a[A-1+1+A];
z=a[A-1+1+A+A];
cout<<x<<" "<<y<<" "<<z<<endl;

}
in++;


}
}

brother!
your list(inp) is not sorted coz input in the list is not a integer make that int(x) for x in input().split().accordingl make some changes now cox your input is integer now .
def run()
n = cus_input()
n = n // 4
**inp = sorted([x for x in input().split()])

res = []
for i in range(1, 4):
idx = n * i
if check_feasibility(inp, idx):
res.append(inp[idx])
else:
return -1
return res

That was a good find. Thank you for looking into my code. @shashadwivedi
Appreciate that.