Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.2 kB
2
Indexable
Never
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.util.Collections;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    static HashMap <Integer, Integer> hm = new HashMap<Integer, Integer>();
      static void countFreq(int a[], int n)
   {
        for (int i=0; i<n; i++)
            if (hm.containsKey(a[i]) )
                hm.put(a[i], hm.get(a[i]) + 1);
            else hm.put(a[i] , 1);
    }
    static int query(int x)
    {
        if (hm.containsKey(x))
            return hm.get(x);
        return 0;
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		for(int i=0;i<t;i++)
		{
		    int n=in.nextInt();
		    int k=in.nextInt();
		    int arr[]=new int[n];
		    for(int j=0;j<n;j++)
		    {
		        arr[j]=in.nextInt();
		    }
		   
		    Arrays.sort(arr);
		    int checker = arr[n-k];
		    
		    
		    countFreq(arr,n);
		    
		    int c= query(checker);
		    
		    
		    
		  
		    int ans = k +c-1;
		    System.out.println(ans);
		}
	}
}