about summary refs log tree commit diff
path: root/codechef/qualprel.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-10-20 11:27:47 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-10-20 11:27:47 +0700
commit4c5ed94087a691ce47882786aea64f7b5bf3c130 (patch)
tree6ebb9374e9c9e1d867659a1de166fbe8f6481b19 /codechef/qualprel.c
parent662168dbd56cbeba35bea782d580b0f7cc9a3ac2 (diff)
downloadcp-4c5ed94087a691ce47882786aea64f7b5bf3c130.tar.gz
Bon appétit
Diffstat (limited to 'codechef/qualprel.c')
-rw-r--r--codechef/qualprel.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/codechef/qualprel.c b/codechef/qualprel.c
new file mode 100644
index 0000000..a920592
--- /dev/null
+++ b/codechef/qualprel.c
@@ -0,0 +1,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;
+}