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 collections import Counter
from math import factorial

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

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val
        assert tmp_num<A

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial

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

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
from operator import mul
from functools import reduce

def comb(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_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
from operator import mul
from functools import reduce

def comb(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_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        assert rest!=0
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
from operator import mul
from functools import reduce

def comb(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_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        print(int(factorial(val)/factorial(rest)/factorial(val-rest)))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        print(factorial(val)//factorial(rest)//factorial(val-rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        print(tmp_sum/tmp_num)
        print(factorial(val)//factorial(rest)//factorial(val-rest))
        break
    else:
        tmp_num+=val
        tmp_sum+=key*val

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        break
    else :
        tmp_num+=val
        tmp_sum+=key*val

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    if A<=tmp_num+val<=B:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        break
    elif tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

tmp_sum=0
tmp_num=0

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

tmp_sum=0
tmp_num=0

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=val*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

tmp_sum=0
tmp_num=0

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=val*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

tmp_sum=0
tmp_num=0

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(ans)
    exit()


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=val*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Wrong Answer

Solution code:
import math 

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

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

vl.sort(reverse=True)
if vl[0] == vl[a-1]:
    v = vl[0]
    print(v)
    v_cnt = vl.count(v)
    max_r = min(v_cnt,b)
    ans = 0
    for r in range(1,max_r+1):
        ans += com(v_cnt,r)
    print(ans)

else:
    print(sum(vl[:a])/a)
    last_val = vl[a-1]
    last_val_cnt = vl[0:a].count(last_val)
    all_last_val_cnt = vl.count(last_val)
    print(com(all_last_val_cnt,last_val_cnt))

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
print(sum(A[:a]) / a)
comb = 1
for i in range(a):
    comb *= d[A[i]]
    d[A[i]] -= 1
print(comb)

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b + 1):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
need = []
for i in ans:
    if i[0] == maxx[0]:
        need.append(i[1])
maxx_comb = 0
D = d.copy()
for R in need:
    comd = 1
    for i in range(R):
        comd *= d[A[i]]
        # d[A[i]] -= 1
    # d = D.copy()
    maxx_comb = max(comd, maxx_comb)
print(maxx[0])
print(maxx_comb)

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b + 1):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
need = []
for i in ans:
    if i[0] == maxx[0]:
        need.append(i[1])
maxx_comb = 0
D = d.copy()
for R in need:
    comd = 1
    for i in range(R):
        comd *= d[A[i]]
        d[A[i]] -= 1
    d = D.copy()
    maxx_comb = max(comd, maxx_comb)
print(maxx[0])
print(maxx_comb)

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b + 1):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
need = []
for i in ans:
    if i[0] == maxx[0]:
        need.append(i[1])
maxx_comb = 0
D = d.copy()
for R in need:
    comd = 1
    for i in range(R):
        comd *= d[A[i]]
        d[A[i]] -= 1
    d = D
    maxx_comb = max(comd, maxx_comb)
print(maxx[0])
print(maxx_comb)

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b + 1):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
comd = 1
for i in range(maxx[1]):
    comd *= d[A[i]]
    d[A[i]] -= 1
print(maxx[0])
print(comd)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b + 1):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
comd = 1
for i in range(maxx[1]):
    comd *= d[A[i]]
print(maxx[0])
print(comd)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
A=V[:a]
B=V[:b]
ave=sum(A)/a
print(ave)
C=[[0]*51 for _ in range(51)]
C[0][0]=1
for i in range(50):
    C[i+1][0]=1
    C[i+1][i+1]=1
    for j in range(i):
        C[i+1][j+1]=C[i][j]+C[i][j+1]
if A[0]==A[-1]:
    ans=0
    x=B.count(A[0])
    for i in range(a,x+1):
        ans+=C[x][i]
else:
    x=V.count(A[-1])
    y=A.count(A[-1])
    ans=C[x][y]
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial 
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
def cmb(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
v.sort(reverse=True)
print(sum(v[:a])/a)
cntv,cntr=0,0
for i in range(n):
    if i<a:
        if v[i]==v[a-1]:
            cntv+=1
    else:
        if v[i]==v[a-1]:
            cntr+=1
#print(cntv,cntr)
if cntv<a:
    print(cmb(cntv+cntr,cntv))
else:
    ans=0
    for r in range(a,a+cntr+1):
        ans+=cmb(cntv+cntr,r)
    print(ans)

Submission status: Wrong Answer

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

from decimal import Decimal as de
l=sorted(list(map(int,input().split())),reverse=1)
fact=[1]
for i in range(1,51):
    fact.append(fact[-1]*i)
if len(set(l))==1:

    print(l[0])
    print(sum(fact[n]//(fact[i]*fact[n-i]) for i in range(a,b+1)))
    exit()
ave=de(str(sum(l[:a])))/a
print(ave)
from collections import Counter as co
y=co(l[:a])[l[a-1]]
x=co(l)[l[a-1]]
print(fact[x]//(fact[y]*fact[x-y]))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

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

avg=sum(v[:A])/A
cnt_A=v[:A].count(v[A-1])
cnt_v=v.count(v[A-1])
cnt=0
if cnt_A==A:
    for i in range(cnt_A,cnt_v+1):
        cnt+=cmb(cnt_v,i)
else:
    cnt+=cmb(cnt_v,cnt_A)
print(avg)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
max_mean=sum(v[-a:])/a
print(max_mean)
from collections import Counter
cva=Counter(v[-a:])
cv=Counter(v)
import math
def ncr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 選んだa個が全て同じ値なら
if v[-a]==max_mean:
  ans=0
  for k in range(a,cv[v[-a]]+1):
    ans+=ncr(cv[v[-a]],k)
  print(ans)
else:
  # aこの中で一番小さな数字は何個あるか。
  k0=cva[v[-a]]
  k1=cv[v[-a]]
  ans=ncr(k1,k0)
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact

N, A, B = map(int,input().split())
V = list(map(int,input().split()))
if all([V[0] == i for i in V]):
    print(V[0])
    ans = 0
    for i in range(A, B+1):
        ans += factorial(N)//(factorial(N-i)*factorial(i))
    print(ans)
    sys.exit()

V.sort(reverse = True)
print(sum(V[:A]) / A)

c1 = Counter(V[:A])
c2 = Counter(V)

print(factorial(c2[V[A-1]])//(factorial(c2[V[A-1]]-c1[V[A-1]])*factorial(c1[V[A-1]])))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    from collections import Counter
    from scipy.misc import comb

    N,A,B = [int(i) for i in input().split()]
    V = [int(i) for i in input().split()]

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    from collections import Counter
    from scipy.misc import comb

    N,A,B = [int(i) for i in input().split()]
    V = [int(i) for i in input().split()]

    V.sort(reverse = True)
    max_list = V[0:A]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max < a:
            max_list = V[0:i]
            max = a
    print("{:.6f}".format(max))

    ans = 1
    max_list = Counter(max_list).most_common()
    for i in range(len(max_list)):
        ans *= comb(V.count(max_list[i][0]),max_list[i][1])
    print(int(ans))

Submission status: Wrong Answer

Solution code:
import statistics
import math

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

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

result = 0
mean_min = statistics.mean(v[0:a])
for i in range(a,b+1):
  st_mean = statistics.mean(v[0:i])
  if mean_min == st_mean:
    v_n = v.count(v[a])
    v_r = v[0:i-1].count(v[a])
    result += combinations_count(v_n,v_r)
  else:
    break
print(mean_min)
print(result)

Submission status: Wrong Answer

Solution code:
import statistics
import math

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

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

result = 0
mean_min = statistics.mean(v[0:a])
for i in range(a,b):
  st_mean = statistics.mean(v[0:i])
  if mean_min == st_mean:
    v_n = v.count(v[a])
    v_r = v[0:i+1].count(v[a])
    result += combinations_count(v_n,v_r)
  else:
    break
print(mean_min)
print(result)

Submission status: Wrong Answer

Solution code:
import itertools, bisect
from fractions import Fraction
from math import factorial


def comb(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)

Ave = [Fraction(a, i) for i, a in enumerate(itertools.accumulate(V), 1)]
max_num = max(Ave[A - 1:B])
max_indices = [i for i, v in enumerate(Ave) if v == max_num]

Vm = [-v for v in V]
C = 0
for ind in max_indices:
    l = bisect.bisect_left(Vm, Vm[ind])
    r = bisect.bisect_right(Vm, Vm[ind])
    C += comb(r - l, ind - l + 1)
print(float(max_num))
print(C)

Submission status: Wrong Answer

Solution code:
def ncr(n, r):
  res = 1
  for i in range(1, n + 1):
    res *= i
  for i in range(1, r + 1):
    res //= i
  for i in range(1, n - r + 1):
    res //= i
  return res
n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
print(sum(v[0:a]) / a)
if v[0] == v[a - 1]:
  b = min(b, v.count(v[0]))
  ans = 0
  for i in range(a, b + 1):
    ans += ncr(b, i)
  print(ans)
else:
  k = v.count(v[a - 1])
  r = v[0:a].count(v[a - 1])
  print(ncr(k, r))

Submission status: Wrong Answer

Solution code:
import math


def check(m, A, V):
    # whether we can get `m` for mean of values
    cnt, x = 0, 0
    for v in V[:A]:
        x += v - m
        cnt += 1
    return x >= 0


def comb(n, k):
    if k > n - k:
        return comb(n, n - k)
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)


def main():
    N, A, B = list(map(int, input().split(' ')))
    V = list(map(int, input().split(' ')))
    V.sort(reverse=True)
    # calculate max average value by binary search
    eps = 10 ** (-6)
    ok, ng = 0, 10 ** 16
    while (ng - ok) / ng > eps:
        mid = (ok + ng) / 2
        if check(mid, A, V):
            ok = mid
        else:
            ng = mid
    ans_v = ok
    # calculate pattern number
    min_target_v = V[A - 1]
    target_v_cnt = sum([1 if v == min_target_v else 0 for v in V])
    selected_target_v_cnt = sum([1 if v == min_target_v else 0 for v in V[:A]])
    ans_pattern = 0
    for i in range(B - A + 1):
        if target_v_cnt < selected_target_v_cnt + i:
            break
        ans_pattern += comb(target_v_cnt, selected_target_v_cnt + i)
    # answer
    print(ans_v)
    print(ans_pattern)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N,A,B = LI()
    v = LI()
    d = {}
    for x in v:
        if x in d: d[x] += 1
        else: d[x] = 1

    dx = sorted(d.items(),reverse=True)

    ans = 0.0
    cnt = 0
    for k in range(A,B+1):
        c = 0
        i = 0
        x = 0
        while c < k:
            c += dx[i][1]
            if c >= k:
                x += dx[i][0] * (dx[i][1] - (c-k))
                cnt_i = math.factorial(dx[i][1]) / math.factorial(c-k) / math.factorial(dx[i][1] - (c-k))
                av = round(x/k,7)
                if av > ans:
                    ans = av
                    cnt = cnt_i
                elif av == ans:
                    cnt += cnt_i
            else:
                x += dx[i][0] * dx[i][1]
            i += 1
    print(ans)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N,A,B = LI()
    v = LI()
    d = {}
    for x in v:
        if x in d: d[x] += 1
        else: d[x] = 1

    dx = sorted(d.items(),reverse=True)

    ans = 0.0
    cnt = 0
    for k in range(A,B+1):
        c = 0
        i = 0
        x = 0
        while c < k:
            c += dx[i][1]
            if c >= k:
                x += dx[i][0] * (dx[i][1] - (c-k))
                cnt_i = int(math.factorial(dx[i][1]) / math.factorial(c-k) / math.factorial(dx[i][1] - (c-k)))
                av = round(x/k,7)
                if av > ans:
                    ans = av
                    cnt = cnt_i
                elif av == ans:
                    cnt += cnt_i
            else:
                x += dx[i][0] * dx[i][1]
            i += 1
    print(ans)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
print(sum(v[:A]) / A)
for i in range(N):
  v[i] *= -1

target = v[A-1]
count = min(B, bisect_right(v, target)) - bisect_left(v, target)
erabu = A - bisect_left(v, target)
erabu1 = min(erabu, count-erabu)

if erabu1 == 0:
  print(1)
  exit()

start = 1
for i in range(erabu1):
  start = start * (count-i) // (i+1)

if v[0] != v[A-1]:
  print(start)
  exit()

ans = start
now = start
for i in range(count - erabu):
  now = now * (count-erabu1-i) // (i+erabu1+1)
  ans += now
  
print(ans)

Submission status: Wrong Answer

Solution code:
comb_memo = {}
def comb(n, r):
  global comb_memo
  if (n, r) in comb_memo:
    return comb_memo[(n, r)]
  else:
    r = min(r, n-r)
    res = 1
    for _ in range(r):
      res *= n
      n -= 1
    for i in range(1, r+1):
      res //= i
    comb_memo[(n, r)] = res
    comb_memo[(n, n-r)] = res
    return res

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

mu = sum(v[:A]) / A
R = A-1
for i in range(A, N):
  if v[i] == mu:
    R = i
  else:
    break

R += 1
ans = 0
if R > A:
  for i in range(A, B+1):
    ans += comb(R, i)
else:
  min_v = v[A-1]
  n = v.count(min_v)
  need = v[:A].count(min_v)
  ans += comb(n, need)

print(mu)
print(ans)

Submission status: Wrong Answer

Solution code:
f_memo = {0:1, 1:1}
def f(x):
  global f_memo
  if x in f_memo:
    return f_memo[x]
  else:
    res = x * f(x-1)
    f_memo[x] = res
    return res

comb_memo = {}
def comb(n, r):
  global comb_memo
  if (n, r) in comb_memo:
    return comb_memo[(n, r)]
  else:
    a = f(n)
    b = f(n-r)
    c = f(r)
    res = a // b // c
    comb_memo[(n, r)] = res
    return res


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

mu = sum(v[:A]) / A
R = A-1
for i in range(A, B):
  if v[i] == mu:
    R = i
  else:
    break

R += 1
ans = 0
if R > A:
  for i in range(A, R+1):
    ans += comb(R, i)
else:
  min_v = v[A-1]
  n = v.count(min_v)
  need = v[:A].count(min_v)
  ans += comb(n, need)

print(mu)
print(ans)