-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeForces-1475E.cpp
More file actions
65 lines (52 loc) · 1.29 KB
/
CodeForces-1475E.cpp
File metadata and controls
65 lines (52 loc) · 1.29 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by abdob on 10/29/2022.
//
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;
int pw(int a, int b, int m = MOD) {
if (b == 0)return 1;
if (b & 1)return a * pw(a, b - 1) % m;
return pw(a * a % m, b / 2);
}
int inverse(int a) {
return pw(a, MOD - 2);
}
int fact[maxn], inv[maxn];
void preprocess(int lmt) {
fact[0] = 1;
for (int i = 1; i <= lmt; i++)fact[i] = (fact[i - 1] * i) % MOD;
inv[lmt] = inverse(fact[lmt]);
for (int i = lmt - 1; i >= 0; i--)inv[i] = (i + 1) * inv[i + 1] % MOD;
}
int C(int n, int r) {
if (r > n)return 0;
return fact[n] * inverse(fact[r] * fact[n - r] % MOD) % MOD;
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sort(v.rbegin(), v.rend());
int val = v[k - 1];
int ct = count(v.begin(), v.end(), val);
int need = 0;
for (int i = k - 1; i >= 0; i--)need += v[i] == val;
cout << C(ct, need) << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
preprocess(maxn);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}