about summary refs log tree commit diff
path: root/codechef/chefinsq.py
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-09-16 20:32:51 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-09-16 20:32:51 +0700
commit4b8df7227736b7c41af56e053d40decc309fe7f9 (patch)
tree9d2823886c29ddd3ac8cd8a5503ad130238d012e /codechef/chefinsq.py
parent029688e143109344989b1529259e391822abb0aa (diff)
downloadcp-4b8df7227736b7c41af56e053d40decc309fe7f9.tar.gz
Recovery (2010)
Diffstat (limited to 'codechef/chefinsq.py')
-rwxr-xr-xcodechef/chefinsq.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/codechef/chefinsq.py b/codechef/chefinsq.py
new file mode 100755
index 0000000..04fd5ef
--- /dev/null
+++ b/codechef/chefinsq.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+from bisect import bisect_left, bisect_right
+from functools import reduce
+from math import factorial
+
+
+def c(n, r):
+    return reduce(int.__mul__, range(n, n - r, -1), 1) // factorial(r)
+
+
+for t in range(int(input())):
+    n, k = map(int, input().split())
+    a = sorted(map(int, input().split()))
+    l, r = bisect_left(a, a[k - 1]), bisect_right(a, a[k - 1])
+    print(c(r - l, min(k - l, r - k)))