Problem
There are students in a class, where the -th student has a score of .
The -th student will boast if and only if the number of students scoring less than or equal is greater than the number of students scoring greater than .
Find the number of students who will boast.
Input Format
- The first line contains - the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer - the number of students.
- The second line of each test case contains integers - the scores of the students.
Output Format
For each test case, output in a single line the number of students who will boast.
Constraints
Sample 1:
3 3 100 100 100 3 2 1 3 4 30 1 30 30
3 2 3
Explanation:
- Test case : All three students got the highest score. So all three of them will boast.
- Test case : Only the student with score will not be able to boast.
- Test case : Only the student with score will not be able to boast.
Program :
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int l = sc.nextInt();
int m[] = new int[l];
for(int i=0; i<m.length; i++)
{
m[i] = sc.nextInt();
}
int count = 0;
for(int i=0; i<l; i++)
{
int lower=0, higher=0;
for(int j=0; j<l; j++)
{
if(m[j] <= m[i])
lower++;
else
higher++;
}
if(lower>higher)
count++;
}
System.out.println(count);
}
}
}
0 Comments