You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ai
11
+
12
+
followers.
13
+
14
+
Since Masha has a limited budget, she can only sign a contract with k
15
+
16
+
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.
17
+
18
+
Help her, find the number of ways to select k
19
+
20
+
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).
21
+
22
+
For example, if n=4
23
+
, k=3, a=[1,3,1,2], then Masha has two ways to select 3
24
+
25
+
bloggers with the maximum total number of followers:
26
+
27
+
conclude contracts with bloggers with numbers 1
28
+
29
+
, 2 and 4. In this case, the number of followers will be equal to a1+a2+a4=6
30
+
.
31
+
conclude contracts with bloggers with numbers 2
32
+
, 3 and 4. In this case, the number of followers will be equal to a2+a3+a4=6
33
+
34
+
.
35
+
36
+
Since the answer can be quite large, output it modulo 10^9+7.
37
+
38
+
39
+
APPROACH:
40
+
well the logic for the ques is easy but the implementaion to make the NCR
41
+
in the range of h is hard.
42
+
the logic was to count till k and then further count the freq of continued no.
43
+
the ans would be sCt .
44
+
to make it in range i got the chance to learn modular operations about division
45
+
to do that i learned fermat's little theoram to calculate inverse of the denominator
46
+
i also learned bin exponantion to calculate a^b in log(b)time which is extreamely
47
+
eff way of calculating powers
48
+
49
+
Time Complexity:O(n+s+t+logbase2(m))which is O(n) only as log(m) is appx 30;
0 commit comments