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: Wrong Answer

Solution code:
from scipy.misc import comb
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

# 価値の平均の最大値を出力
print(sum(V[:A]) / A)

# A番目に大きいものがいくつあるか
C_a = V.count(V[A - 1])

# A番目より大きいものがいくつあるか
C_than_a = len([v for v in V if v > V[A - 1]])

ans = 0
for i in range(A, B + 1 - C_than_a):
    ans += comb(C_a, i, 1)
print(max(ans, 1))

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i + 1
    for i in range(A, idx + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i + 1
    print(idx)
    for i in range(A, idx + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, B):
        if v[i] == v[A]:
            idx = i
    for i in range(A, idx + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i
    for i in range(A, idx + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i
    for i in range(A, idx + 1):
        ans2 += combinations(N, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[-1]:
    for i in range(A, B + 1):
        ans2 += combinations(N, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[-1]:
    for i in range(1, N + 1):
        ans2 += combinations(N, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

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

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[-1]:
    for i in range(1, N + 1):
        ans2 += combinations(N, i)
else:
    ans2 = combinations(num1 + num2, num2)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
import math

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

v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[0:A])/A)

cnt=v.count(v[0])
cnt2=v.count(v[A-1])
V=v[0:A]
cnt3=V.count(v[A-1])

def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        
if cnt<A:
    print(combinations_count(cnt2, cnt3))
elif cnt==A:
    print(1)
elif cnt>A:
    ans=0
    for i in range(A,min(cnt,B)):
        ans+=combinations_count(cnt,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
from collections import defaultdict
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
vd = defaultdict(int)
for i in range(N):
    vd[v[i]] += 1
vd=sorted(vd.items(),key=lambda x:x[0],reverse=True)
ave,i,cnt = 0,0,0
for v,c in vd:
    if A<=cnt+c:
        break
    cnt += c
    ave += v*c
    i += 1
ans = 0
if i==0:
    ave = vd[i][0]
    ub = max(B,vd[i][1])
    for i in range(A-1,B):
        ans += factorial(ub)//(factorial(ub-(i+1))*factorial(i+1))
else:
    ave += vd[i][0]*(A-cnt)
    ave /= A 
    ans = factorial(vd[i][1])//(factorial(vd[i][1]-(A-cnt))*factorial(A-cnt))
print(ave)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
from collections import defaultdict
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
vd = defaultdict(int)
for i in range(N):
    vd[v[i]] += 1
vd=sorted(vd.items(),key=lambda x:x[0],reverse=True)
ave,i,cnt = 0,0,0
for v,c in vd:
    if A<=cnt+c:
        break
    cnt += c
    ave += v*c
    i += 1
ans = 0
if i==0:
    ave = vd[i][0]
    ub = min(B,vd[i][1])
    for i in range(A-1,ub):
        ans += factorial(ub)//(factorial(ub-(i+1))*factorial(i+1))
else:
    ave += vd[i][0]*(A-cnt)
    ave /= A 
    ans = factorial(vd[i][1])//(factorial(vd[i][1]-(A-cnt))*factorial(A-cnt))
print(ave)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
#c = n! / (r! * (n - r)!)
def com(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

v.sort(reverse=True)

anum=0
onum=0
for i in range(N):
    if v[i]==v[A-1]:
        anum+=1
    else:
        onum+=1
    if v[i]<v[A-1]:
        break
ans=0
if v[0]==v[A-1]:
    for i in range(A,min(B,anum)+1):
        ans+=com(anum,i)
#    print('aaa')
else:
    ans+=com(anum,A-onum)
    
print(sum(v[:A])/A)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1L
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1L
        else:
            v_nums[v[i]] = 1L

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave_s = 0
    max_count = 0L
    sum_count = 0
    max_n = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0L
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1L
            else:
                last_num_count += 1L


        if max_count == 0 or abs(n * max_ave_s - max_n *s)/float(max_n * max_ave_s) <= 1e-6:
            max_ave_s = s
            max_n = n
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.6f" %(max_ave_s/max_n)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1L
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1L
        else:
            v_nums[v[i]] = 1L

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0L
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0L
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1L
            else:
                last_num_count += 1L

        ave = float(s)/float(n)
        if max_count == 0 or abs(ave - max_ave) < 1e-6 or abs(ave - max_ave)/max_ave < 1e-6:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.7f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1L
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1L
        else:
            v_nums[v[i]] = 1L

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0L
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0L
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1L
            else:
                last_num_count += 1L

        ave = float(s)/float(n)
        if max_count == 0 or abs(ave - max_ave) < 1e-6:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.7f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if max_count == 0 or abs(ave - max_ave) < 1e-6:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.7f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if max_count == 0 or abs(ave - max_ave) < 1e-7:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.7f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if ave > max_ave or abs(ave - max_ave) < 1e-7:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.8f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if ave >= max_ave:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%.8f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if ave >= max_ave:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print "%f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1
        else:
            v_nums[v[i]] = 1

    v.sort(reverse = True)
##    s =[0 for i in range(N)]
##    s[0] = v[0]
##    for i in range(1, N):
##        s[i] = s[i -1] + v[i]

    max_ave = 0
    max_count = 0
    for n in range(A, B+1):
        last_num = -1
        last_num_count = 0
        s = 0L
        for i in range(n):
            s += v[i]
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1
            else:
                last_num_count += 1

        ave = float(s)/float(n)
        if ave >= max_ave:
            max_ave = ave
            max_count += Comb(v_nums[last_num], last_num_count)
##        if abs(ave - max_ave) <= 1e-8:
##            max_count += 1
##        elif max_ave < ave:
##            max_count = 1
##            max_ave = ave

    print max_ave
    print max_count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import math
N, A, B = map(int, input().split())
value = list(map(int, input().split()))
value.sort()
value.reverse()
valuetot = 0
for i in range(A):
    valuetot += value[i]
valueave = valuetot/A
value.append(0)
v = value[A-1]
C = collections.Counter(value)
vcount = C[v]

for i in range(A):
    if value[i] == v:
        vindex = i
        break

def permutation(n,r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator


def pattern(a):
    c = collections.Counter(value[:a])
    return permutation(vcount, c[v])

v0 = value[0]
v0len = 0
for i in range(N):
    if v0 == value[i]:
        v0len = i + 1
    else:
        break


if v0len >= A:
    ans = 0
    for i in range(B):
        if v0 == value[i]:
            ans += permutation(v0len, i+1)


elif value[A-1] != value[A]:
    ans = 1

else:
    ans = pattern(A)

print(valueave)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math
N, A, B = map(int, input().split())
value = list(map(int, input().split()))
value.sort()
value.reverse()
valuetot = 0
for i in range(A):
    valuetot += value[i]
valueave = valuetot/A
value.append(0)
v = value[A-1]
C = collections.Counter(value)
vcount = C[v]

for i in range(A):
    if value[i] == v:
        vindex = i
        break

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

def pattern(a):
    c = collections.Counter(value[:a])
    return permutation(vcount, c[v])

v0 = value[0]
v0len = 0
for i in range(N):
    if v0 == value[i]:
        v0len = i + 1
    else:
        break


if v0len > A:
    ans = 0
    for i in range(A, B+1):
        if v == value[i]:
            ans += permutation(v0len, i)
        else:
            break

elif value[A-1] != value[A]:
    ans = 1

else:
    ans = pattern(A)

print(valueave)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math
N, A, B = map(int, input().split())
value = list(map(int, input().split()))
value.sort()
value.reverse()
valuetot = 0
for i in range(A):
    valuetot += value[i]
    valueave = valuetot/A

v = value[A-1]
C = collections.Counter(value)
vcount = C[v]

for i in range(A):
    if value[i] == v:
        vindex = i
        break

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

def pattern(a):
    c = collections.Counter(value[:a])
    return permutation(vcount, c[v])

v0 = value[0]
v0len = 0
for i in range(N):
    if v0 == value[i]:
        v0len = i + 1
    else:
        break


if v0len > A:
    ans = 1
    for i in range(A, B):
        if v == value[i]:
            ans += permutation(v0len, i)
        else:
            break

elif value[A-1] != value[A]:
    ans = 1

else:
    ans = pattern(A)

print(valueave)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=a.count(a[0])
if c!=A:
    print(math.factorial(b)/(math.factorial(c)*math.factorial(b-c)))
else:
    l=[]
    i=min([b-c,B-A])
    for k in range(0,i+1):
        l.append(math.factorial(b)/(math.factorial(c+k)*math.factorial(b-c-k)))
    print(sum(l))

Submission status: Wrong Answer

Solution code:
import math
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=a.count(a[0])
print(math.factorial(b)/(math.factorial(c)*math.factorial(b-c)))

Submission status: Wrong Answer

Solution code:
import math
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=lst.count(a[0])
print(math.factorial(b)/(math.factorial(c)*math.factorial(b-c)))

Submission status: Wrong Answer

Solution code:
def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)
def conb(n,r):
    return fact(n)//(fact(r)*fact(n-r))

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
d_all = {}
for i in range(N):
    if v[i] not in d_all:
        d_all[v[i]] = 0
    d_all[v[i]] += 1
import numpy as np
avg = np.cumsum(np.array(v))
avg = avg.astype('float128')
for i in range(N):
    avg[i]=int(avg[i])/(i+1)
    
avg = avg[A-1:B]
ans = max(avg)
print(ans)
indices = np.where(avg==ans)[0]
ans = 0
for index in indices:
    d_use = {}
    use = A + index
    v_use = v[:use]
    choose=1
    for item in v_use:
        if item not in d_use:
            d_use[item] = 0
        d_use[item] += 1
    for item in d_use:
        choose *= conb(d_all[item],d_use[item])
    ans += choose

print(ans)