1475E.md (3413B)
1 Source: https://codeforces.com/problemset/problem/1475/E 2 3 E. Advertising Agency 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers. 22 23 Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers. 24 25 Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers). 26 27 For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers: 28 29 * conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$. 30 * conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$. 31 32 Since the answer can be quite large, output it modulo $10^9+7$. 33 34 Input 35 36 The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow. 37 38 The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) — the number of bloggers and how many of them you can sign a contract with. 39 40 The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) — the number of followers of each blogger. 41 42 It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. 43 44 Output 45 46 For each test case, on a separate line output one integer — the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. 47 48 Example 49 50 Input 51 52 ``` 53 3 54 4 3 55 1 3 1 2 56 4 2 57 1 1 1 1 58 2 1 59 1 2 60 ``` 61 62 Output 63 64 ``` 65 2 66 6 67 1 68 ``` 69 70 Note 71 72 The test case is explained in the statements. 73 74 In the second test case, the following ways are valid: 75 76 * conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$; 77 * conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$; 78 * conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$; 79 * conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$; 80 * conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$; 81 * conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$. 82 83 In the third test case, the following ways are valid: 84 85 * concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.