From 4b8df7227736b7c41af56e053d40decc309fe7f9 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 16 Sep 2019 20:32:51 +0700 Subject: Recovery (2010) --- codechef/chefinsq.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 codechef/chefinsq.py (limited to 'codechef/chefinsq.py') 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))) -- cgit 1.4.1