```
enter code here
#include<stdio.h>
#include<stdlib.h>
int partition(int *arr, int start, int end){
int i=start+1, j=end, temp;
while(i<j){
while(arr[i]>=arr[start]){
i++;
}
while(arr[j]<arr[start]){
j--;
}
if(i<j){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
j--;
}
}
temp=arr[start];
arr[start]=arr[j];
arr[j]=temp;
return j;
}
void quicksort(int *arr, int start, int end){
if(start<end){
int index=partition(arr, start, end);
quicksort(arr, start, index-1);
quicksort(arr, index+1, end);
}
}
int main(){
int i, t, n, k, count, *ptr;
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &k);
ptr=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++){
scanf("%d", &ptr[i]);
}
count=0;
quicksort(ptr, 0, n-1);
i=0;
while(ptr[i]>=ptr[k-1]){
count++;
i++;
}
printf("%d\n", count);
}
return 0;
}
```

asked
**15 Dec '18, 15:56**

2★hardikti

1●1

accept rate:
0%