Problem:


Score : 400 points

Problem Statement

You are given N items.

The value of the i-th item (1 \leq i \leq N) is v_i.

Your have to select at least A and at most B of these items.

Under this condition, find the maximum possible arithmetic mean of the values of selected items.

Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.  

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

The input is given from Standard Input in the following format:

N A B
v_1
v_2
...
v_N

Output

Print two lines.

The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.

The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.

There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

There can be multiple ways to select items so that the mean of the values will be maximized.

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1



Sample input:
5 2 2
1 2 3 4 5


Sample output:
4.500000
1

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
import scipy.misc

def comb(n, r):
    return scipy.misc.comb(n, r, exact=True)

n, a, b, *v = map(int, sys.stdin.read().split())

def main():
    v.sort()

    ma = v[n-a:n]
    yield sum(ma) / a

    lo = ma[0]
    hi = ma[-1]

    res = 0
    lo_cnt = bi_r(v, lo) - bi_l(v, lo)
    if lo == hi:
        for c in range(a, min(b, lo_cnt) + 1):
            res += comb(lo_cnt, c)
    else:
        allowed_cnt = bi_r(ma, lo)
        res = comb(lo_cnt, allowed_cnt)
    
    yield res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter

N,A,B = map(int, input().split())

V = list(map(int, input().split()))

V.sort(reverse=True)

c = Counter(V)
max_average = sum(V[:A]) / A
c_max = Counter(V[:A])

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret

# A個選んだ時の最大平均値が、全て同じ価値で構成されている時
# この場合は、全体の個数の取り方が、A〜min(B, V_maxの個数)と、複数ある
if len(c_max) == 1:
    # A個選ぶ、A+1個選ぶ、...、min(B, c[V[0]])個選ぶ　の和が答え
    ans = 0
    n = c[V[0]]
    for r in range(A, min(B, n)+1):
        ans += nCr(n,r)


# 最大平均値が複数の価値から作られる場合、価値が大きい順から全て使われる価値がいくつかと、中途半端に使われる価値が一つになる
# なので、中途半端に選ばれるものの選び方を数え上げる
# この時、全体の個数はA個固定（さらに何かを追加すると平均が減少するため）
else:
    
    # 最大平均値を構成する、最小の価値を探す
    tmp = list(c_max.keys())
    tmp.sort()
    # 最小の値
    min_num = tmp[0]
    # 最小以外の数字で何個選んでいるか
    cnt = 0
    for i in tmp[1:]:
        cnt += c_max[i]
    remaining = A - cnt

    ans = nCr(c[min_num], remaining)

print(max_average)
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, A, B, *v = map(int, open(0).read().split())

v.sort(reverse=True)
answer = sum(v[:A]) / A
n = 0

if v[0] == v[A - 1]:
    N = v.count(v[0])
    n = cmb(N, min(N, B))
    tmp_cmb = n
    for i in range(min(B, N) - 1, A - 1, -1):
        tmp = N - i
        tmp_cmb = tmp_cmb * (i + 1) // tmp
        n += tmp_cmb
else:
    n = cmb(v.count(v[A - 1]), A - v.index(v[A - 1]))

print(answer)
print(n)

Submission status: Accepted

Solution code:
from math import factorial
import bisect
def cmb(n,r):
  if n<0 or r<0:
    return 0
  else:
    return factorial(n)//factorial(n-r)//factorial(r)
n,a,b=map(int,input().split())
x = list(map(int,input().split()))
ans=0
x.sort(reverse=True)
print(sum(x[:a])/a)
if n==a:
  print(1)
elif x[0]==x[a]:
  for i in range(n):
    if x[0] != x[i]:
      k=i
      break
  else:
    k=n
  for i in range(a,min(k+1,b+1)):
    ans+=cmb(k,i)
  print(ans)
elif x[a-1] == x[a]:
  y=sorted(x)
  x1=bisect.bisect_left(y,x[a])
  x2=bisect.bisect_right(y,x[a])
  print(cmb(x2-x1,a-(n-x2)))
else:
  print(1)

Submission status: Accepted

Solution code:

def combination_table(N):
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(i):
            if j==0 or j==i:
                C[i][j]=1
            else:
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    return C[2:]

if __name__ == '__main__':
    N,A,B=list(map(int,input().split()))
    V=list(map(int,input().split()))
    V.sort(reverse=True)
    temp=V[:A]
    max_mean=sum(temp)/A
    count=0
    C=combination_table(N+2)

    if V[0]!=V[A-1]:
        temp_1=V.count(V[A-1])
        temp_2=V[:A].count(V[A-1])
        count+=C[temp_1-1][temp_2]
        """temp_1=V.count(V[0])
        temp_2=V[:A].count(V[0])
        count+=C[temp_1-1][temp_2]"""
    elif V[0]==V[A-1]:
        for i in range(A,B+1):
            temp_1=V.count(V[0])
            count+=C[temp_1-1][i]

    print(max_mean)
    print(count)

Submission status: Accepted

Solution code:
from math import factorial

N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(sum([factorial(n) // factorial(r) // factorial(n - r)
               for r in range(A, min(n, B) + 1)]))
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))

Submission status: Accepted

Solution code:
import bisect
import math
N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())))
ave = sum(v[-A:]) / A
print(ave)
leftA = bisect.bisect_left(v, v[-A])
rightA = bisect.bisect_right(v, v[-A])

def comb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n-r)

ans = 0
if v[-A] == v[-1]:
    for i in range(A, min(rightA-leftA, B) + 1):
        ans += comb(rightA-leftA, i)
    print(ans)
else:
    print(comb(rightA-leftA, A+rightA-N))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
V = sorted([int(a) for a in input().split()])[::-1]

fa = [1]
for i in range(1, 60): fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(sum(V[:A])/A)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i])*A == sum(V[:A])*i]))

Submission status: Accepted

Solution code:
from itertools import accumulate as ac
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    if list(ac([v-m for v in V]))[A-1] >= 0:
        l = m
    else:
        r = m

fa = [1]
for i in range(1, 60):
    fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(l/t)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i]) == l * i]))

Submission status: Accepted

Solution code:
import math
def pcount(n, r):
    return math.factorial(n) // (math.factorial(r)* math.factorial(n - r))

n, a, b = map(int, input().split())
L = [int(i) for i in input().split()]
L.sort(reverse=True)

T = L[:a]
print(sum(T)/a)

s = 0
Tmin = min(T)
countTminT = T.count(Tmin)
countTminL = L.count(Tmin)

if a == 1 and countTminL == 1:
  s = 1
elif countTminT == a:
  for i in range(a,b+1):
    if countTminL+1 == i:
      break
    s += pcount(countTminL, i)
else:
  s += pcount(countTminL, countTminT)

print(s)

Submission status: Accepted

Solution code:
def solve() -> 'max(averages), count(max(averages))':
    from collections import Counter
    from functools import lru_cache
    n, a, b = map(int, input().split())
    v = tuple(sorted(map(int, input().split()), reverse=True))

    def max_ave_x() -> 'max(average),{counts_to_make_max_average}':
        ret = -1
        t = 0
        max_i = set()
        for i, e in enumerate(v, 1):
            t += e
            if a <= i:
                ave = t / i
                if ret < ave:
                    max_i = {i}
                    ret = ave
                elif ret == ave:
                    max_i.add(i)
            if i == b:
                break
        return ret, max_i

    @lru_cache(maxsize=None)
    def combination(n, r):
        if n < r or r < 0:
            return 0
        if r > n - r:
            return combination(n, n - r)
        if r == 0:
            return 1
        if r == 1:
            return n
        return combination(n - 1, r - 1) * n // r

    max_, indices = max_ave_x()

    ret = 0

    c1 = Counter(v)
    for i in indices:
        c2 = Counter(v[:i])
        t = 1
        for chr_ in c2:
            t *= combination(c1[chr_], c2[chr_])
        ret += t

    return max_, ret


print(*solve(), sep='\n')

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[:a])/a)
 
import math
def cmb(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))
x,y=v.count(v[a-1]),v[:a].count(v[a-1])
if v[0]==v[a-1]:
   ans=sum(cmb(x,i) for i in range(a,min(b,x)+1))
else:
    ans=cmb(x,y)
print(ans)

Submission status: Accepted

Solution code:
import math

nab = [int(x) for x in input().split()]
n = nab[0]
a = nab[1]
b = nab[2]
counts = []
nums = [int(x) for x in input().split()]
means = []
nums.sort(reverse = True)
for i in range(a, b+1):
  means.append(sum(nums[:i])/i)
  counts.append(int(math.factorial(nums.count(nums[i-1]))/(math.factorial(nums[:i].count(nums[i-1]))*math.factorial(nums.count(nums[i-1])-nums[:i].count(nums[i-1])))))

maxim = max(means)
print(maxim)
k = 0
count = 0
while k<len(means):
  if means[k]==maxim:
    count+=counts[k]
  k+=1
print(count)

#print(means.count(max(means)))

'''
def C(n, k):
  return C(n-1, k-1) + C(n-1, k)
  
for n in range(MAX_N):
  for k in range(MAX_K):
    C[n][k] = C[n-1][k-1] + C[n-1][k]
'''

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    ave = 0
    for i in range(A):
        ave += sort_v[i]
    ave = ave / A
    ans = 0
    if sort_v[0] == sort_v[A-1]:
        cnt = v.count(sort_v[A-1])
        for i in range(A, min(cnt,B)+1):
            ans += cmb(cnt,i)
    else:
        cnt = v.count(sort_v[A-1])
        ind = sort_v.index(sort_v[A-1])
        ans = cmb(cnt, A - ind)
    print(ave)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
from math import factorial

def comb(n,k):
    if(k<0 or n<k): return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

def resolve():
    n,a,b=map(int,input().split())
    V=list(map(int,input().split()))
    V.sort(reverse=1)
    m=sum(V[:a])/a
    print(m)

    cnt=0
    for key,iter in groupby(V):
        k=len(list(iter))
        if(cnt+k>=a): break
        cnt+=k

    ans=0
    if(cnt==0):
        for i in range(a-cnt,min(k,b-cnt)+1):
            ans+=comb(k,i)
    else:
        ans=comb(k,a-cnt)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
from math import factorial

def comb(n,k):
    if(k<0 or n<k): return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

def resolve():
    n,a,b=map(int,input().split())
    V=list(map(int,input().split()))
    V.sort(reverse=1)
    m=sum(V[:a])/a
    print(m)

    cnt=0
    for key,iter in groupby(V):
        k=len(list(iter))
        if(cnt+k>=a): break
        cnt+=k

    ans=0
    K=min(k,b-cnt)
    if(cnt==0):
        for i in range(a-cnt,K+1):
            ans+=comb(k,i)
    else:
        ans=comb(k,a-cnt)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
V = [int(v) for v in input().split()]

V.sort(reverse=True)
s = 0
for i in range(A):
    s += V[i]
    idx = i
    
av = s/A
for i in range(A, B):
    if V[i] < av:
        break
    s += V[i]
    av = s/(i+1)
    idx = i
    
cnt_up = 0
cnt_same = 0
for i in range(N):
    if V[i] > V[idx]:
        cnt_up += 1
    elif V[i] == V[idx]:
        cnt_same += 1
        
print(av)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


if cnt_up > 0:
    ans = cmb(cnt_same, A-cnt_up)
else:
    ans = 0
    for i in range(A, B+1):
        if cnt_same < i:
            break
        ans += cmb(cnt_same, i)
        
print(ans)

Submission status: Accepted

Solution code:
def comb(n,r):
    if n < r:
        return 0
    si,bo = 1,1
    for i in range(n):
        si *= i+1
    for i in range(r):
        bo *= i+1
    for i in range(n-r):
        bo *= i+1
    return si//bo

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)

print(sum(v[:A])/A)
n = 0
r = 0
for i in range(A):
    if v[i] == v[A-1]:
        r += 1
        n += 1
for i in range(A,N):
    if v[i] == v[A-1]:
        n += 1
ans = 0
if v[0] != v[A-1]:
    print(comb(n,r))
    exit()
for _ in range(A,B+1):
    ans += comb(n,r)
    r += 1
print(ans)

Submission status: Accepted

Solution code:
import math
def comb(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))

n, a, b = map(int,input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
max_avg = sum(v[:a]) / a
min_v = min(v[:a])

ans = 0
for i in range(a, b+1):
    if max_avg != sum(v[:i]) / i: break
    cnt1 = v[:i].count(min_v)
    cnt2 = v.count(min_v)
    ans += comb(cnt2, cnt1)

print(max_avg)
print(int(ans))

Submission status: Accepted

Solution code:
from math import factorial

def nCr(n, r) :
    return factorial(n)//(factorial(r)*factorial(n-r))


n,a,b = map(int,input().split())
V = sorted(list(map(int,input().split())), reverse=True)

L1, L2 = V[:a], V[a:]

ans1 = sum(L1)/a

minv = min(L1)
x = L1.count(minv)
y = L2.count(minv)

ans2 = 0

if x == a :
    for i in range(x, x+min(y, b-a)+1) :
        ans2 += nCr(x+y, i)
else :
    ans2 = nCr(x+y, x)

print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N,A,B = map(int,input().split())
V = list(map(int,input().split()))

V.sort(reverse=True)

ans1 = sum(V[:A])/A

ans2 = 1
cnt = V.count(V[0])
if cnt > A:
    ans2 = 0
    for i in range(A,min(B,cnt)+1):
        tmp = 1
        for j in range(i):
            tmp *= cnt-j
            tmp //= j+1
        ans2 += tmp
else:
    cnt1 = V.count(V[A-1])
    cnt2 = V[:A].count(V[A-1])
    if cnt1 > 1:
        for i in range(cnt2):
            ans2 *= cnt1-i
            ans2 //= i+1

print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
import math
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
x.reverse()

j=a+1
moto=0
h=0
d=x[a-1]
asd=0
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(moto/a)
if moto/a==x[a-1]:
  for i in range(a,b+1):
    if l-i>=0:
      asd+=math.factorial(l)//(math.factorial(l-i)*math.factorial(i))
  print(asd)
else:
  print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h)))

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def comb2(n,r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def examD():
    N, A, B = LI()
    v = LI(); v.sort(reverse = True)
    ans = sum(v[:A])/A
    d = defaultdict(int)
    for s in v:
        d[s] +=1
#    print(d)
    cur = A
    for i in v:
        if cur<=d[i]:
            break
        else:
            cur -=d[i]
    if i!=max(v):
        ansC = comb2(d[i],cur)
    else:
        ansC = 0
        for j in range(A,min(B,d[i])+1):
            ansC += comb2(d[i],j)
    print(ans)
    print(ansC)


import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
ans=0
for i in range(a):
    ans+=v[i]
ans/=a
print(ans)
if v[0]==v[a-1]:
    count=0
    for i in range(n):
        if v[i]==v[0]:
            count+=1
    cnt=0
    for i in range(a,min(b,count)+1):
        cnt+=cmb(count,i)
    print(cnt)
else:
    count=0
    for i in range(n):
        if v[i]==v[a-1]:
            count+=1
    for i in range(n):
        if v[i]==v[a-1]:
            l=i
            break
    cnt=cmb(count,a-l)
    print(cnt)

Submission status: Accepted

Solution code:
from math import factorial as fact
def comb(n, r):
  denom = fact(r)*fact(n-r)
  return fact(n)//denom

n = list(map(int, input().split()))
l = list(map(int, input().split()))

l = sorted(l)

summ = 0

for i in range(n[1]):
  summ+=l[len(l)-1-i]

avg = float(summ)/n[1]
last =  l[len(l)-n[1]]
lasts = l.count(last)
more = sum(1 for i in l if i>last)
print(avg)
if more!=0:
  answer = comb(lasts, n[1]-more)
  print(answer)
else:
  b= min(lasts, n[2])
  answer = 0
  for i in range(n[1], b+1):
    answer += comb(lasts, i)
  print(answer)

Submission status: Accepted

Solution code:
import math
from collections import Counter

def comb(n,r):
    f=math.factorial
    return f(n)//(f(r)*f(n-r))

N,A,B=list(map(int,input().split()))
v=sorted(list(map(int,input().split())),reverse=True) # 全要素

m=sum(v[:A])/A # 平均値の最大値(A個の場合)

c=Counter(v[:A]) # 大きい方からA個の要素のみ
# この中の最小の要素は，v[A-1]
a=v[A-1]

n=v.count(a) # v内のaの個数
r=c[a] # c内のaの個数

# n個のaの中から，r個を選ぶ方法
ans=comb(n,r)

# n個のaの中から，r個以上min(r+(B-A),n)個以下を選ぶ方法
# ※これはv[0]==v[A]のときのみ
if v[0]==v[A]:
    for i in range(r+1,min(r+(B-A)+1,n+1)):
        ans+=comb(n,i)

print(m)
print(ans)

Submission status: Accepted

Solution code:
nCr = {}
def cmb(n, r):
    if n < r:
        return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = sum(values[:a]) / a
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

if min_value == maximum_mean:
    ans = 0
    for r in range(a, b+1):
        ans += cmb(full, r)
else:
    ans = cmb(full, accepted)

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean

nCr = {}
def cmb(n, r):
    if n < r:
        return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

if min_value == maximum_mean:
    ans = 0
    for r in range(a, b+1):
        ans += cmb(full, r)
else:
    ans = cmb(full, accepted)

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

# def cmb(n, r):
#     if n - r < r: r = n - r
#     if r == 0: return 1
#     if r == 1: return n

#     numerator = [n - r + k + 1 for k in range(r)]
#     denominator = [k + 1 for k in range(r)]

#     for p in range(2,r+1):
#         pivot = denominator[p - 1]
#         if pivot > 1:
#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot
#                 denominator[k] /= pivot

#     result = 1
#     for k in range(r):
#         if numerator[k] > 1:
#             result *= int(numerator[k])

#     return result
nCr = {}
def cmb(n, r):
    if n < r:
        return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]



if min_value == maximum_mean:
    ans = 0
    for r in range(a, b+1):
        ans += cmb(full, r)
else:
    ans = cmb(full, accepted)

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
d = dd(int)
sd = dd(int)
res = 1
nCr = {}
def cmb(n, r):
  global nCr
  if r == 0 or r == n: return 1
  if r == 1: return n
  if (n,r) in nCr: return nCr[(n,r)]
  nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
  return nCr[(n,r)]

for i in range(N):
  d[v[i]] += 1
r = sum(v[: A])
s = v[: A]
sdsum = 0
for t in s:
  sd[t] += 1
  sdsum += 1
kss = sorted(sd.keys())
#print(d, sd)
f = 0
j = -1
for k in range(A, B + 1):
  j += 1
  t = 1
  for i in range(len(kss)):
    a = kss[i]
    if d[a] < sd[a] + j:
      f = 1
      break
    t *= cmb(d[a], sd[a] + j)
    #print(d[a], sd[a] + j)
  if f:
    break
  res += t
print(r / A)
print(res - 1)

Submission status: Accepted

Solution code:
from math import factorial


def comb(n, r):
    if n < r:
        return 0
    return factorial(n) // (factorial(r) * factorial(n - r))


N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
cnt = 0
cnt2 = 0
for i in range(N):
    if v[i] > v[A]:
        cnt += 1
    if v[i] == v[A]:
        cnt2 += 1
avg_max = sum(v[:A]) / A
print(avg_max)
ans = 0
if v[0] != v[A]:
    print(comb(cnt2, A-cnt))
else:
    for i in range(A, min(B+1, cnt2 + 1)):
        ans += comb(cnt2, i)
    print(ans)

Submission status: Accepted

Solution code:
from math import factorial
N,A,B = map(int,input().split())
V = sorted(list(map(int,input().split())),reverse=True)
C = {}
for i in range(N):
    if V[i] not in C:
        C[V[i]] = 0
    C[V[i]] += 1
v = V[A-1]
avg = sum(V[:A])/A
print(avg)
cnt = V[:A].count(v)
if cnt<A:
    tot = factorial(C[v])//factorial(cnt)//factorial(C[v]-cnt)
else:#cnt==A
    tot = 0
    for j in range(A,min(B,C[v])+1):
        tot += factorial(C[v])//factorial(j)//factorial(C[v]-j)
print(tot)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())

import math
import functools
 
def cmb(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))
 
v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[:a])/a)
x,y=v.count(v[a-1]), v[:a].count(v[a-1])
if v[0]==v[a-1]:
    ans=sum( cmb(x,i)    for i in range(a,min(b,x)+1))

else:
    ans=cmb(x,y)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

def comb(n: int, k: int) -> int:
    ans = 1
    for i in range(1, k+1):
        ans *= n - i + 1
        ans //= i
    return ans

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
c = Counter(v)

cand = defaultdict(int)
for m in range(a, b+1):
    s = sum(v[:m])
    k = len(list(filter(lambda x: x == v[m-1], v[:m])))
    l = c[v[m-1]]

    cand[s / m] += comb(l, k)

# print(cand)
ans1 = max(cand.keys())
print(ans1)
print(cand[ans1])

Submission status: Accepted

Solution code:
import math, collections
n, a, b = map(int, input().split())
list_v = [int(v) for v in input().split()]
list_v.sort(reverse=True)
list_ave = []
list_num = []
for i in range(a, b+1):
  temp_ave = sum(list_v[:i]) / len(list_v[:i])
  list_ave.append(temp_ave)
  list_num.append(i)
max_ave = max(list_ave)
print(max_ave)

list_target = [list_num[i] for i, v in enumerate(list_ave) if v == max_ave]
count = collections.Counter(list_v)
sort_count = sorted(count.items(), reverse=True)
res = 0
for one_num in list_target:
  r = one_num
  for o in sort_count:
    temp = r - o[1]
    if temp <= 0:
      res += math.factorial(o[1]) // (math.factorial(o[1]-r) * math.factorial(r))
      break
    else:
      r -= o[1]
print(res)

Submission status: Accepted

Solution code:
def combinations(N):
    comb = [[0] * (N + 1) for _ in range(N + 1)]
    comb[0][0] = 1
    for i in range(1, N + 1):
        for j in range(i + 1):
            comb[i][j] += comb[i - 1][j]
            if j > 0:
                comb[i][j] += comb[i - 1][j - 1]
    return comb


nCk = combinations(60)

N, A, B, *V = map(int, open(0).read().split())

V.sort(reverse=True)

num = V.count(V[A - 1])

ans = 0
if V[0] == V[A - 1]:
    ans = sum(nCk[num][A:B + 1])
else:
    a = V[:A].count(V[A - 1])
    ans = nCk[num][a]

ave = sum(V[:A]) / A

print("{:.9f}".format(ave))
print(ans)

Submission status: Accepted

Solution code:
def combinations(N):
    comb = [[0] * (N + 1) for _ in range(N + 1)]
    comb[0][0] = 1
    for i in range(1, N + 1):
        for j in range(i + 1):
            comb[i][j] += comb[i - 1][j]
            if j > 0:
                comb[i][j] += comb[i - 1][j - 1]
    return comb


nCk = combinations(60)

N, A, B, *V = map(int, open(0).read().split())

V.sort(reverse=True)

num = V.count(V[A - 1])

ans = 0
if V[0] == V[A - 1]:
    for i in range(A, B + 1):
        ans += nCk[num][i]
else:
    a = V[:A].count(V[A - 1])
    ans = nCk[num][a]

ave = sum(V[:A]) / A

print("{:.9f}".format(ave))
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def na(): return map(int,stdin.readline().split())

def ns(): return stdin.readline().strip()

n,a,b=na()
v=list(na())
v.sort()
tot=0
last=0
for i in range(a):
    tot+=v[-(i+1)]
    last=v[-(i+1)]

com=[]
q=100
for i in range(q):
    com.append([0]*q)

for i in range(q):
    com[i][0]=1
    for j in range(1,q):
        com[i][j]=com[i-1][j-1]+com[i-1][j]

print("{:.9f}".format(tot/a))
lct=0
large=0
for w in v:
    if w>last:large+=1
    if w==last:lct+=1
ret=0
if large==0:
    for i  in range(a,b+1):
        if 0 <= i-large <= lct:
            ret+=com[lct][i-large]
else :
    ret=com[lct][a-large]
print(ret)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
u=sorted(list(map(int,input().split())))[::-1]
v=sum(u[:a])/a
print(v)
f=[1]
for i in range(50):f+=[f[-1]*(i+1)]
x=u.count(u[a-1])
if u[0]==u[a-1]:print(sum(f[x]//(f[x-i]*f[i])for i in range(a,b+1)))
else:y=u[:a].count(u[a-1]);print(f[x]//(f[x-y]*f[y]))

Submission status: Accepted

Solution code:
import math

def nCr(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N,A,B = map(int,input().split())

v = list(map(int,input().split()))

minlis = []
maxlis = []

v.sort()

for i in range(N):

    if i < N-A:
        minlis.append(v[i])

    else:
        maxlis.append(v[i])


ave = sum(maxlis) / A
print (ave)


x = min(maxlis)

xinmax = 0
xinmin = 0

for i in minlis:
    if i == x:
        xinmin += 1

for i in maxlis:
    if i == x:
        xinmax += 1

if ave == x and xinmin != 0:

    ans = 0

    for i in range(xinmax + xinmin - A + 1):

        i += A
        if i > B:
            break

        ans += nCr(xinmin+xinmax,i)

    print (ans)

else:

    print (nCr(xinmin+xinmax,xinmax))

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
# print(l)
# print(l[:a])
print(sum(l[:a]) / a)
l_w = l[:a]
ans = 0
nCr = {}


def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]


if l[0] == l[-1]:
    for i in range(a, b + 1):
        ans += cmb(b, i)
elif l_w[0] == l_w[-1]:
    for i in range(a, min(b + 1,l.count(l_w[-1])+1)):
        ans += cmb(l.count(l_w[-1]), i)
else:
    ans = cmb(l.count(l_w[-1]), l_w.count(l_w[-1]))
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)

    kai = [1] * (N+1)

    for i in range(1, N+1):
        kai[i] = i * kai[i-1]

    ans1 = sum(v[:A]) / A

    dic = {}
    for t in v:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    dic = sorted(dic.items(), reverse=True)
    # print(dic)
    tmp = 0
    for i in range(N):
        tmp += dic[i][1]
        if tmp >= A:
            ind = i
            must = A - (tmp - dic[i][1])
            max_ = min(B, tmp) - (tmp - dic[i][1])
            break
    n = dic[ind][1]
    if ind == 0:
        ans2 = 0
        # nCA ~ nCmax_
        for i in range(A, max_+1):
            ans2 += (kai[n] // kai[n - i]) // kai[i]
    else:
        # nCmust
        ans2 = (kai[n] // kai[n - must]) // kai[must]
    
    print(ans1)
    print(ans2)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import factorial

def getlist():
	return list(map(int, input().split()))

N, A, B = getlist()
v = sorted(getlist())

ans1 = 0
for i in range(A):
	ans1 += v[-1 - i]
ans1 = ans1 / A
print(ans1)

if v[-1] != v[- A]:
	i = 0
	while True:
		if v[- A + i] == v[- A]:
			i += 1
		else:
			 break
	ans2 = factorial(v.count(v[- A])) // factorial(i) // factorial(v.count(v[- A]) - i)

else:
	ans2 = 0
	n = v.count(v[-1])
	for i in range(A, B + 1):
		if v[- i] == v[- A]:
			ans2 += factorial(n) // factorial(n - i) // factorial(i)

		else:
			 break

print(int(ans2))