about summary refs log tree commit diff
path: root/codechef/qualprel.c
blob: a920592c7b6f0c348875d95bda0126b1e3fb0170 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <stdio.h>

int cmp(const void *x, const void *y)
{
	long tmp = *(long *) y - *(long *) x;
	return tmp ? tmp / labs(tmp) : tmp;
}

int main()
{
	int t, k, n, i;
	long *s = malloc(10000 * sizeof(long));
	scanf("%d\n", &t);

	while (t--) {
		scanf("%d %d\n", &n, &k);
		for (i = 0; i < n; i++)
			scanf("%ld", s + i);
		qsort(s, n, sizeof(long), cmp);
		for (i = k; i < n && s[k - 1] == s[i]; i++);
		printf("%d\n", i);
	}

	return 0;
}