Code chef Lunch Time : Problem :-Drumpf for President! Answer (solution)

Read problems statements in Mandarin ChineseRussian and Vietnamese as well.

Donald Drumpf has spent the entire summer lobbying to gather votes for the upcoming student government election. At his University, there are a total of N students. Each student in the university casts a vote. The size of student government is determined by the number of students that get at least K votes.
Each person that receives at least K votes is given a post in the student government. The Dean noticed that every year, there are a few students who vote for themselves. He decided to add a rule to disqualify any such individuals who vote for themselves i.e they cannot be part of the student government.
You are given an array A, where Ai denotes the person who the i-th person voted for. Can you compute the size of the student government?


The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
For each test case, first line consists of two space separated integers NK.
Second line consists of N space separated integers denoting the array A, where i-th integer denotes Ai.


For each test case, output a single line containing an integer corresponding to the size of the student government.


  • 1 ≤ T ≤ 100
  • 1 ≤ K ≤ N
  • 1 ≤ Ai ≤ N


Subtask #1: (30 points)
  • 1 ≤ N ≤ 3
Subtask #2: (70 points)
  • 1 ≤ N ≤ 100


3 2
2 1 2
2 1
1 2



In first test case, there are 3 students. A student must receive at least 2 votes to be part of the student government. Student 1 votes for student 2, student 2 votes for student 1 and student 3 votes for student 2. Thus, Student 2 receives 2 votes and is the only one eligible for student government.
In second test case, although both students receive the required amount of votes, they are both disqualified as they had voted for themselves. Thus, size of the student government is 0.

If you want answer then follow below link
                                                           ANSEwRE HERE