Average Flex Solution

Problem

There are N students in a class, where the i-th student has a score of A_i.

The i-th student will boast if and only if the number of students scoring less than or equal A_i is greater than the number of students scoring greater than A_i.

Find the number of students who will boast.

Input Format

  • The first line contains T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains a single integer N - the number of students.
  • The second line of each test case contains N integers A_1, A_2, \dots, A_N - the scores of the students.

Output Format

For each test case, output in a single line the number of students who will boast.

Constraints

  • 1 \leq T \leq 1000
  • 1 \leq N \leq 100
  • 0 \leq A_i \leq 100

Sample 1:

Input
Output
3
3
100 100 100
3
2 1 3
4
30 1 30 30
3
2
3

Explanation:

  • Test case 1: All three students got the highest score. So all three of them will boast.
  • Test case 2: Only the student with score 1 will not be able to boast.
  • Test case 3: Only the student with score 1 will not be able to boast.





Program :


 #include <stdio.h>


int main(void) {

// your code goes here

int t,n;

int i,j;

scanf("%d",&t);

while(t--)

{

   scanf("%d",&n);

   int a[n];

   for(i=0;i<n;i++)

   {

       scanf("%d",&a[i]);

   }

   int c=0,c1=0,c2=0;

   for(i=0;i<n;i++)

   {

       for(j=0;j<n;j++)

       {

           if(a[i]>=a[j])

           {

               c1++;

           }

           else

           {

               c2++;

           }

       }

       if(c1>c2)

           {

               c++;

           }

           c1=0;

           c2=0;

   }

   printf("%d\n",c);

}

return 0;

}


Post a Comment

0 Comments