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 math
import functools

def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
ave = sum(v[:a]) / a
x, y = v.count(v[a-1]), v[:a].count(v[a-1])

if v[0] == v[a-1]:
    comb = sum([C(x,i) for i in range(a,min(b,x)+1)])
else:
    comb = C(x,y)

print(ave)
print(comb)

Submission status: Accepted

Solution code:
import math
def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = []
    for i in range(A, B+1):
        L += [[sum(v[:i]) / i, v[:i]]]
    LMAX = []
    x = L[0][0]
    for i in L:
        if i[0] == x : LMAX += [i]
    ans = 0
    for i in LMAX:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(LMAX[0][0])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from scipy.misc import comb

def combb(a, b):
	s1, s2 = 1, 1
	for i in range(a - b + 1, a + 1):
		s1 *= i
	for i in range(1, b + 1):
		s2 *= i
	return s1 / s2


n, a, b = map(int, raw_input().split())
l = map(int, raw_input().split())

l.sort(reverse = True)
s = 0

for i in range(a):
	s += l[i]

s = float(s) / a
print s

q = l[i]
c, d = 0, 0

for i in range(n):
	if (i < a) and (l[i] == q):
		c += 1
	if (i >= a) and (l[i] == q):
		d += 1

e = c + d

if q < s:
	print combb(e, c)
else:
	ss = 0
	for i in range(a, b + 1):
		ss += combb(e, i)
	print ss

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
 
def combination(a, b):
    u, d = 1, 1
    for i in range(b):
        u *= a - i
        d *= b - i
    
    return u // d
 
s_i = sum(v[:A])
c_i = A
ans = 0
a = A
while s_i * a == sum(v[:a]) * c_i and a <= B:
    last_num = None
    c = 0
    for i in range(a):
        n = v[i]
        if n == last_num:
            c += 1
        else:
            c = 0
        
        last_num = n
 
    ans += combination(v.count(v[a - 1]), c + 1)
    a += 1
 
print(sum(v[:A]) / A)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin 
n,a,b = map(int,stdin.readline().split())
aa = map(int,stdin.readline().split())
aa.sort()
aa.reverse()
di = {}
fa = [1]
for i in xrange(1,100):
    fa.append(i*fa[-1])
def ncr(n,r):
    return fa[n]/(fa[r]*fa[n-r])
for i in aa:
    di[i] = di.get(i,0) + 1 
def ways(m):
    b = aa[:m]
    co = b.count(b[-1])
    ll = aa.count(b[-1])
    return sum(b),ncr(ll,co)

num = 0 
den = 1
ans = 0 
for i in xrange(a,b+1):
    nn,ww = ways(i)
    dd = i 
    if nn * den > dd * num:
        num = nn 
        den = dd 
        ans = ww 
    elif nn * den == dd * num:
        ans += ww 
print "%.10f"%((num*1.0)/den)
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/python

import math
import sys

def combination(a, b):
    return math.factorial(a)/(math.factorial(b) * math.factorial(a - b))

def main(argv):
    line = sys.stdin.readline().rstrip("\n")

    while line:
        n, a, b = map(lambda x: int(x), line.split(" ", 3))
        values = map(lambda x: int(x), raw_input().split(" "))

        sorted_values = sorted(values, reverse=True)
        mean = (float)(sum(sorted_values[0:a])) / a
        print mean

        counts = {}
        for v in sorted_values[0:a]:
            if not v in counts:
                counts[v] = 0
            counts[v] += 1

        count = 0
        if len(counts.keys()) == 1:
            c = 0
            for v in sorted_values:
                if v == sorted_values[0]:
                    c += 1
                else:
                    break

            for i in xrange(a, min(b, c) + 1):
                count += combination(c, i)
        else:
            c_s = 0
            c_e = 0
            for v in sorted_values:
                if v > sorted_values[a - 1]:
                    c_s += 1
                elif v == sorted_values[a - 1]:
                    c_e += 1
                elif v < sorted_values[a - 1]:
                    break

            count += combination(c_e, a - c_s)
        print count

        print " "

        line = sys.stdin.readline().rstrip("\n")

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
import math

# def comboSum(n, chooseMin, chooseMax):
# 	print(n, chooseMin, chooseMax)
# 	ways = 0
# 	for i in range(chooseMin, chooseMax + 1):
# 		localWays = math.factorial(n) // math.factorial(i) // math.factorial(n - i)
# 		ways += localWays
# 	return ways


def avg(L, atLeast, atMost):
	if (L.count(max(L)) >= atLeast):
		print(max(L))
		ways = 0
		for i in range(atLeast, min(atMost, L.count(max(L))) + 1):
			localWays = math.factorial(L.count(max(L))) // math.factorial(i) // math.factorial(L.count(max(L)) - i)
			ways += localWays
		print(ways)
		return
	L.sort(reverse=True)
	last = L[atLeast - 1]
	print(sum(L[:atLeast]) / atLeast)
	firstIndex = L.index(last)
	# lastIndex = len(L) - (sorted(L).index(last)) - 1
	n = L.count(last)
	i = atLeast - firstIndex
	print(math.factorial(n) // math.factorial(i) // math.factorial(n - i))

[N, atLeast, atMost] = list(map(lambda x: int(x), input().split()))
L = list(map(lambda x: int(x), input().split()))
avg(L, atLeast, atMost)

Submission status: Accepted

Solution code:
import math
def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = []
    for i in range(A, B+1):
        L += [[sum(v[:i]) / i, v[:i]]]
    LMAX = []
    x = L[0][0]
    for i in L:
        if i[0] == x : LMAX += [i]
    ans = 0
    for i in LMAX:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                
                
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(LMAX[0][0])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def fact(n):
    if n <= 1:
        return 1
    else:
        return n * fact(n - 1)

def comb(n, r):
    return fact(n) // fact(r) // fact(n - r)

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

Vs = list(reversed(sorted(Vs)))
cnt = {}
for v in Vs:
    if v not in cnt:
        cnt[v] = 1
    else:
        cnt[v] += 1

dict = {}
for i in range(A, B + 1):
    dict[i] = sum(Vs[:i]) / i

avg = 0
for k in dict:
    if avg < dict[k]:
        avg = dict[k]

cand = []
for k in dict:
    if avg - dict[k] < 1E-6:
        cand.append(k - 1)

ans = 0
for c in cand:
    x = 0
    for i in range(c + 1):
        if Vs[i] == Vs[c]:
            x += 1
    ans += comb(cnt[Vs[c]], x)

print(avg)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math

def C(n1, n2):
    ans = 1
    for i in range(n1, n1-n2, -1):
        ans *= i
    for j in range(1, n2+1):
        ans //= j
    return ans

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

avg = 0.0
way = 0
for num_of_choice in range(A, B + 1):
    choiced = []
    for n in range(num_of_choice):
        choiced.append(Vs[n])
    if choiced[0] == choiced[-1]:
        avg = choiced[0]
        way += C(Vs.count(choiced[0]), num_of_choice)
    else:
        if way != 0:
            break
        border = choiced[-1]
        n1 = Vs.count(border)
        n2 = choiced.count(border)
        avg = sum(choiced) / num_of_choice
        way = C(n1, n2)
        break

print("{:.12f}".format(avg))
print(way)

Submission status: Accepted

Solution code:
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(num_v) // math.factorial(num_v - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= math.factorial(num_cnt) \
                           // math.factorial(num_cnt - cnt) \
                           // math.factorial(cnt)
        print(max_avg_ptn)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

def fact(n):
    if n == 0:
        return 1
    return reduce(lambda a,b:a*b, range(1, n + 1))

def C(n, r):
    return fact(n) // fact(n - r) // fact(r)

N, A, B = map(int, input().split(" "))
v = sorted(map(int, input().split(" ")), reverse=True)
S = sum(v[:A])
print(S / A)

used = v[:A].count(v[A-1])
all = v.count(v[A-1])

if v[0] == v[A - 1]:
    ub = min(B, all)
    print(sum(C(all, i) for i in range(A, ub + 1)))
else:
    print(C(all, used))

Submission status: Accepted

Solution code:
_, a, b = map(int, raw_input().split())

v = map(int, raw_input().split())

v.sort(key=lambda x: -x)

s = 0
for i in xrange(a):
    s += v[i]

print '{:.6f}'.format(s / float(a))

# num = v.count(v[a-1])
# print 'num', num
# print v[:a].count(v[a-1])

n = v.count(v[a-1])
k = v[:a].count(v[a-1])
# k = min(k, n)

import operator as op
def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

if v[0] == v[a-1]:
    ways = 0
    for k in xrange(a, min(b, n) + 1):
        # print n, k, ncr(n, k)
        ways += ncr(n, k)
    print ways
else:
    k = (v[:a].count(v[a-1]))
    print ncr(n, k)

Submission status: Accepted

Solution code:
import sys
from math import factorial

def solve():
    N, A, B = map(int, input().split())
    v = [int(i) for i in input().split()]
    v.sort(reverse=True)

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

    onaji = v.count(v[0])

    if onaji < A:
        k = v[:A].count(v[A - 1])
        n = v.count(v[A - 1])
        cnt = binom(n, k)
    else:
        cnt = 0

        for i in range(A, min(onaji, B) + 1):
            cnt += binom(onaji, i)

    print('{:.8f}'.format(ave_max))
    print(cnt)


def binom(n, k):
    return (factorial(n) // factorial(n - k)) // factorial(k)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
S = V[-A:]
avgmax = sum(S) / A
print(avgmax)

Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
	C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
	print(C)
else:
	i = A
	C = 0
	while i <= B and V[-i] == min(S):
		c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
		C = C + c
		i = i + 1
	print(C)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
last = data[a-1]
p = sum(map(lambda x: x == last, data[:a]))
if data[0] == last:
  q = sum(map(lambda x: x == last, data[:b]))
else:
  q = p  
z = sum(map(lambda x: x == last, data))

r = 1
res = 0
for i in range(q):
  r *= z - i
  r //= i + 1
  if i >= p-1:
    res += r  
    
print(s/k)
print(res)

Submission status: Accepted

Solution code:
def nCk(n,k):
    ret=1
    if n<k or k<0 or n<0:return 0
    if n-k<k:
        k=n-k
    for i in xrange(n,n-k,-1):
        ret=ret*i
    fact=[1]*(k+1)
    for i in xrange(1,k+1):
        fact[i]=fact[i-1]*i
    return ret/fact[k]

n,a,b=map(int,raw_input().split())
v=map(int,raw_input().split())
v=sorted(v,reverse=True)
if a==n:
    print float(sum(v[0:a]))/a
    print 1
    exit()

num=0
l=0
if v[a]==v[a-1]:
    start=a-1
    for i in xrange(a-1,0,-1):
        if v[i]==v[i-1]:
            start=i-1
        else:
            break
    if start==0:
        cnt=1
        for i in xrange(n-1):
            if v[i]==v[i+1]:
                cnt+=1
        pt=0
        for i in xrange(a,b+1):
            if cnt<i:break
            pt+=nCk(cnt,i)
        print float(sum(v[0:a]))/a
        print pt
    else:
        cnt=1
        for i in xrange(start,n-1):
            if v[i]==v[i+1]:
                cnt+=1
        pt=0
        for i in xrange(a-start,b+1):
            if start+i<a:continue
            if start+i>a:break
            pt+=nCk(cnt,i)
        print float(sum(v[0:a]))/a
        print pt

else:
    print float(sum(v[0:a]))/a
    print 1

Submission status: Accepted

Solution code:
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v[:a])) == 1:
    print(v[0])
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            cnt += 1
    ans = 0
    for i in range(a,min(b,cnt)+1):
        ans += comb(cnt,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Submission status: Accepted

Solution code:
from fractions import Fraction

def choose(n,r):
    res=1
    for i in range(r):
        res=res*(n-i)//(i+1)
    return res

n,a,b=map(int,input().split())
vs=sorted(map(int,input().split()))

average_max=Fraction(sum(vs[n-a:]),a)
print("{0:.9f}".format(float(average_max)))

res=0
for m in range(a,b+1):
    average=Fraction(sum(vs[n-m:]),m)
    if average<average_max:
        continue
    mn=min(vs[n-m:])
    res+=choose(sum(1 for x in vs if x==mn),
                sum(1 for x in vs[n-m:] if x==mn))
print(res)

Submission status: Accepted

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
# print("{0:.20f}".format(ans))
print(ans)

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

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

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i+1
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]
print(ans2)

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
l=list(map(int,input().split()))

def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

l.sort(reverse = True)
masd = {}
for i in l:
	masd[i] = 0
for i in l:
	masd[i] += 1

res = 0

maxave = 0

task = []

for i in range(A,B+1):
	if maxave < sum(l[:i])/i:
		maxave = sum(l[:i])/i
		task = [i]
	elif maxave == sum(l[:i])/i:
		task.append(i)

for i in task:
	c = 1
	d = {}
	for j in l[:i]:
		d[j] = 0
	for j in l[:i]:
		d[j] += 1

	for j in d.keys():
		c *= nCr(masd[j],d[j])
	res += c

print(maxave)
print(res)

Submission status: Accepted

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
print("{0:.20f}".format(ans))

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

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

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i+1
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]
print(ans2)

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    N,A,B = map(int, input().split())
    values = list(map(int, input().split()))
    values.sort(reverse=True)
    result = 0
    max_values = []
    dic_values = defaultdict(int)
    for x in values:
        dic_values[x] += 1
    for limit in range(A, B + 1):
        res = []
        for i,x in enumerate(values):
            if (i >= limit):
                break
            res.append(x)
        if (result < sum(res) / len(res)):
            result = sum(res) / len(res)
            max_values = res

    print ("%.20lf" % result)
    comb = 0
    for limit in range(A, B + 1):
        res = []
        for i,x in enumerate(values):
            if (i >= limit):
                break
            res.append(x)
        if (result == sum(res) / len(res)):

            res_dic = defaultdict(int)
            for x in res:
                res_dic[x] += 1
            tmp = 1
            for key in res_dic:
                a = dic_values[key]
                b = res_dic[key]
                res = 1
                for x in range(b):
                    res *= a
                    a -= 1
                while (b > 0):
                    res //= b
                    b -= 1
                tmp *= res
            comb += tmp
    print (comb)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
v = list(map(int, input().split()))

dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]
cnt = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0] = 0
cnt[0][0] = 1

for i in range(N):
    for j in range(N - 1, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i+1][j] = dp[i][j]
        cnt[i+1][j] = cnt[i][j]

        ncost = dp[i][j] + v[i]
        if dp[i+1][j+1] < ncost:
            dp[i+1][j+1] = ncost
            cnt[i+1][j+1] = cnt[i][j]
        elif dp[i+1][j+1] == ncost:
            cnt[i+1][j+1] += cnt[i][j]

maxVal = 0
maxCnt = 0
for i in range(A, B + 1):
    if maxVal < dp[N][i] / i:
        maxVal = dp[N][i] / i
        maxCnt = cnt[N][i]
    elif maxVal == dp[N][i] / i:
        maxCnt += cnt[N][i]

print(maxVal)
print(maxCnt)

Submission status: Accepted

Solution code:
from fractions import Fraction

def choose(n,r):
    res=1
    for i in range(r):
        res=res*(n-i)//(i+1)
    return res

n,a,b=map(int,input().split())
vs=sorted(map(int,input().split()))

average_max=Fraction(sum(vs[n-a:]),a)
print("{0:.9f}".format(float(average_max)))

res=0
for m in range(a,b+1):
    average=Fraction(sum(vs[n-m:]),m)
    if average<average_max:
        continue
    mn=min(vs[n-m:])
    res+=choose(sum(1 for x in vs if x==mn),
                sum(1 for x in vs[n-m:] if x==mn))
print(res)

Submission status: Accepted

Solution code:
class Frac(object):
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def eq(self, f):
        return self.a * f.b == f.a * self.b

    def lt(self, f):
        return self.a * f.b > f.a * self.b

    def __repr__(self):
        return '%.6f' % (self.a / self.b)


def factorial(n):
    res = 1
    for i in range(n):
        res *= i+1
    return res


def nCr(n, r):
    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)

res = None
for i in range(A, B+1):
    now = Frac(sum(V[:i]), i)
    if res is None or now.lt(res[0]):
        res = [now]
    elif now.eq(res[0]):
        res.append(now)

cnt = 0
for now in res:
    p = V[:now.b]
    n = len(list(filter(lambda x: x == p[-1], V)))
    r = len(list(filter(lambda x: x == p[-1], p)))
    cnt += nCr(n, r)

print(res[0])
print(cnt)

Submission status: Accepted

Solution code:
def combination(n, r):
    res = 1
    t = r - 1
    while t >= 0:
        res = res * (n - t) // (r - t)
        t -= 1
    return res

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

v.sort()
v.reverse()

t = 0
for i in range(a):
    t += v[i]
t /= a
print(t)

cnt = 0
if v[0] == v[a-1]:
    candidate = 0
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            candidate += 1
        else:
            break
    for i in range(a, min(b, candidate)+1):
        cnt += combination(candidate, i)
else:
    cnt = 0
    first = 50
    last = 0
    for i in range(n):
        if v[i] == v[a-1]:
            first = min(i, first)
            last = max(i, last)
    candidate = last - first + 1
    cnt += combination(candidate, a-first)
print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def nCb(n, b):
    if b > n - b:
        b = n - b
    r = 1
    for k in range(n, n-b, -1):
        r = r * k
    d = 1
    for k in range(1, b+1):
        d = d * k
    return r // d

def main():
    n,a,b = LI()
    v = sorted(LI(),reverse=True)
    if v[0] == v[a-1]:
        t = a-1
        for i in range(a,n):
            if v[0] != v[i]:
                break
            t = i
        t += 1
        r = 0
        for i in range(a,min(b,t)+1):
            r += nCb(t,i)
        return "{}\n{}".format(v[0], r)

    t = 0
    tu = 0
    va = v[a-1]
    for i in range(n):
        if v[i] > va:
            tu += 1
        elif v[i] == va:
            t += 1
        else:
            break
    r = nCb(t,a-tu)
    return "{}\n{}".format(sum(v[:a]) * 1.0 / a, r)



print(main())

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: Runtime Error

Solution code:
import math

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

v.sort(reverse = True)
total = 0

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

for i in range(A):
    total = total + v[i]
else:
    print(total / A)
    
count = 0
min = v[A-1]
number = v.count(min)

if(v.index(min) == 0):
    for i in range(A,B+1):
        count = combinations_count(number,i) + count
    print(count)
else:
    print(combinations_count(number,A - v.index(min)))

Submission status: Runtime Error

Solution code:
import math

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

v.sort(reverse = True)
total = 0

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

for i in range(A):
    total = total + v[i]
else:
    print(total / A)
    
count = 0
min = v[A-1]
number = v.count(min)

if(v.index(min) == 0):
    for i in range(A,B+1):
        count = combinations_count(number,i) + count
    print(count)
else:
    print(combinations_count(number,A - v.index(min)))

Submission status: Runtime Error

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
from math import comb
print(sum(D[:A])/A)
ans=0
if D[0]==D[-1]:
  n=D.count(D[A-1])
  k=V[:A].count(D[A-1])
  print(comb(n,k))
else:
  ans=0
  n=D.count(D[A-1])
  for i in range(A,min(n,B)+1):
    ans+=comb(n,i)
  print(ans)

Submission status: Runtime Error

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
else:
  a=D.count(D[a-1])
  if a>1:
    b=D[:A].count(D[a-1])
    print(math.factorial(a)//(math.factorial(b)*math.factorial(a-b)))
  else:
    print(1)

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
V = sorted([int(x) for x in input().split()],reverse=True)
from statistics import mean
from math import comb
maxmean = mean(V[:A])
way = 1
for i in range(1,B+1-A):
    v = V.pop(0)
    if v != maxmean:
        break
if i > 0:
    same = A + i
    for j in range(A,same):
        way += comb(same, j)
print(maxmean)
print(way)

Submission status: Runtime Error

Solution code:
import statistics
import math
N, A, B = map(int, input().split())
v = [int(x) for x in input().split()]
v.sort()

base = v[N-A:]
rem = v[:N-A]
mean_max = statistics.mean(base)
cnb = 0
while mean_max == statistics.mean(base):
    if len(rem) == 0: break
    same = base.count(base[0])
    extra = rem.count(base[0])
    cnb += math.factorial(same+extra)/math.factorial(same)/math.factorial(extra)
    base.append(rem[len(rem)-1])
    rem = rem.pop
print(mean_max)
print(math.floor(cnb))

Submission status: Runtime Error

Solution code:
import statistics
import math
N, A, B = map(int, input().split())
v = [int(x) for x in input().split()]
v.sort()

base = v[N-A:]
rem = v[:N-A]
mean_max = statistics.mean(base)
cnb = 0
while mean_max == statistics.mean(base) or not len(rem) == 0:
    same = base.count(base[0])
    extra = rem.count(base[0])
    cnb += math.factorial(same+extra)/math.factorial(same)/math.factorial(extra)
    base.append(rem[len(rem)-1])
    rem = rem.pop
print(mean_max)
print(math.floor(cnb))

Submission status: Runtime Error

Solution code:
import statistics
import math
N, A, B = map(int, input().split())
v = [int(x) for x in input().split()]
v.sort()

base = v[N-A:]
rem = v[:N-A]
mean_max = statistics.mean(base)
cnb = 0
while mean_max == statistics.mean(base):
    same = base.count(base[0])
    extra = rem.count(base[0])
    cnb += math.factorial(same+extra)/math.factorial(same)/math.factorial(extra)
    base.append(rem[len(rem)-1])
    rem = rem.pop
print(mean_max)
print(math.floor(cnb))

Submission status: Runtime Error

Solution code:
from math import factorial
n, a, b = map(int, input().split())
V = sorted(map(int, input().split()), reverse=True)

av = sum(V[:a]) / a
print(av)

num = V[a]
m = V.count(num)
k = V[:a].count(num)
#print(m, k, a)
if a != k:
    ans = factorial(m) // (factorial(k) * factorial(m - k))
else:
    ans = 0
    for i in range(a, b+1):
        ans += factorial(m) // (factorial(i) * factorial(m - i))

print(ans)

Submission status: Runtime Error

Solution code:
4 2 3
10 20 10 10