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

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A+1]
ave = sum(S) / A
print(S)
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Runtime Error

Solution code:
import math
 
# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d
 
# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
 
# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)
 
# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)
 
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: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(S)
print(ave)

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

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Runtime Error

Solution code:
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,a,b=map(int,raw_input().split())
v=[int(i) for i in raw_input().split()]
chk=[i for i in set(v)]
chk.sort()
if len(chk)==1:
    print chk[0]*1.0
    print sum(pscl(n)[a:b+1])
    exit()
d={}
for i in v:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
total=ans=tmp=0
t=a
for i in chk[::-1]:
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    else:
        total=total+i*t
        print total*1.0/a
       # print d,t,d[i],b-(a-t),pscl(d[i])
        #print sum(pscl(d[i])[t:min(d[i],b-(a-t))+[0,1][d[i]>b-(a-t)]])
        print pscl(d[i][t])
        break

Submission status: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Runtime Error

Solution code:
'''
Created on 2017/03/26

@author: Tomoya
'''
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    j = A
    while j <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) / ( math.factorial(Vs - i) * math.factorial(i))
        j += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))

Submission status: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    j = A
    while j <= B and V[-i] == min(S):
        C = C + math.factorial(cnt) / ( math.factorial(cnt - i) * math.factorial(i))
        j += 1
    

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    j = A
    while j <= B and V[-i] == min(S):
        C = C + math.factorial(cnt) / ( math.factorial(cnt - i) * math.factorial(i))
        j += 1
    

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))

Submission status: Runtime Error

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    for i in range(A,B+1):
        if V[-i] == min(S):
            break
        
        C = C + math.factorial(cnt) / ( math.factorial(cnt - i) * math.factorial(i))
    

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))

Submission status: Runtime Error

Solution code:
# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    for i in range(A,B+1):
        C = C + math.factorial(cnt) / ( math.factorial(cnt - i) * math.factorial(i))
    

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if a == 1 or goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial
from collections import defaultdict


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

counter = defaultdict(int)
for v in goods:
    counter[v] += 1

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)

Submission status: Runtime Error

Solution code:
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = sum(v[:a])*1.0/a
print res1
res2 = 0
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
if a==v[:a].count(v[a-1]):
    res2 = 0
    for i in range(a,b+1):
        res2 += nCr(v.count(v[a]),i)
    print res2
else:
    print nCr(v.count(v[a-1]),v[:a].count(v[a-1]))

Submission status: Runtime Error

Solution code:
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = sum(v[:a])*1.0/a
print res1
res2 = 0
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
if a==v[:a].count(v[a]):
    res2 = 0
    for i in range(a,b+1):
        res2 += nCr(v.count(v[a]),i)
    print res2
else:
    print nCr(v.count(v[a]),v[:a].count(v[a]))

Submission status: Runtime Error

Solution code:
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = sum(v[:a])*1.0/a
print res1
res2 = 0
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
if a==v[:a].count(v[a]):
    res2 = 0
    for i in range(a,b):
        res2 += nCr(v.count(v[i]),i)
else:
    print nCr(v.count(v[a]),v[:a].count(v[a]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# get two integers separated with half-width break
N, A, B = map(int, raw_input().split())
v = []
combos = []

for i in range(N):
    v.append(int(raw_input()))

def permute(v, L):
    p = []
    for l in L:
        p += [l.append(i) for i in v]
    return p

ll = []
for i in range(B):
    ll = permute(v, ll)
    if i + 1 >= A:
        combos += ll

averages = [sum(j)/len(j) for j in combos]

print(max(averages))
print(averages.count(max(averages)))

Submission status: Runtime Error

Solution code:
from itertools import combinations
N,A,B = [int(i) for i in input().split()]

v = [int(i) for i in input().split()]
v.sort()

if v[-A] != v[-A-1]:
    print(sum(v[-A:]) / A)
    print(1)
elif v[-1] :
    # AAと同じ数のカウント
    # Aよりも大きい数のカウント
    cnt = 0
    bigger = 0
    for i in range(N):
        if v[A] < v[i]:
            bigger += 1
        if v[i] == v[A]:
            cnt += 1

    ans = 0
    mini = min(B, cnt+bigger)
    for i in range(A,mini):
        ans += len(list(combinations(range(cnt), i - bigger)))

    print(sum(v[-A:]) / A)
    print(ans)

Submission status: Runtime Error

Solution code:
import sys

INF = 10**9+7

def k(i):
    if(i == 1):
        return 1
    else:
        return(i * k(i-1))

def comb(n, r):
    if(n == r):
        return 1
    else:
        return k(n) / (k(n-r) * k(r))

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))

n, a, b = nil()

v = nil()

v.sort()
v.reverse()

t = 0
y = []
c = 0
for i in range(a):
    c += v[i]
    t = v[i]
    y.append(t)

ans1 = c/a

c = 0
y = set(y)
ans2 = 0
if(len(y) == 1):
    for i in v:
        if(i == t):
            c+=1
    for i in range (a, b+1):
        ans2 += comb(c, i)
else:
    for i in v:
        if(i == t):
            c+=1
    ans2 = c

print(ans1)
print(int(ans2))

Submission status: Runtime Error

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())

V = list(sorted(V))
ss = None
mm = 0 # max mean
index = 0
def Mean(S):
    return float(sum(S))/len(S)

def Factorial(n):
    if n == 1:
        return 1.0
    else:
        return n*Factorial(n - 1)

def NCR(n, r):
    return int(Factorial(n)/(Factorial(n - r) * Factorial(r)))

for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = subset
        mm = m
        index = i
print '{0:.06f}'.format(mm)
print NCR(V.count(V[-i]), subset.count(V[-i]))

Submission status: Runtime Error

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)) == 1:
    print(v[0])
    ans = 0
    for i in range(a,b+1):
        ans += comb(n,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: Runtime Error

Solution code:
from math import factorial


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

Solution code:
import math

def avg(L, atLeast, atMost):
	if (L.count(max(L)) >= atLeast):
		print(max(L))
		ways = 0
		for i in range(atLeast, atMost + 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)
	print(L.count(last))

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