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 math import factorial as ff
def cc(n,r):
  return ff(n)//ff(n-r)//ff(r)
n,a,b = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse = True)
ans = 0
x = l[:a]
ave = sum(x)/a
m = l.count(x[0-1])
if len(set(x)) == 1:
  for i in range(a,min(b,m)+1):
    ans += cc(m,i)
else:
  p = x.count(x[-1])
  ans = cc(m,p)
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
inf=float('inf')
dp=[-1*inf]*(B+1)
dp[0]=0
from collections import defaultdict
cnt=defaultdict(int)
cnt[(0,0)]=1
ans=0
for i in range(N):
    cntc=cnt.copy()
    dpc=dp.copy()
    for j in range(B):
        if dpc[j]<0:continue
        if dpc[j]+V[i]>=dpc[j+1]:
            dp[j+1]=dpc[j]+V[i]
            cnt[(j+1,dp[j+1])]+=cntc[(j,dpc[j])]
            if j+1>=A:
                ans=max(ans,dp[j+1]/(j+1))
res=0 
for i in range(A,B+1):
    res+=cnt[(i,int(ans*i))]
print(ans)
print(res)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
inf=float('inf')
dp=[-1*inf]*(B+1)
dp[0]=0
from collections import defaultdict
cnt=defaultdict(int)
cnt[(0,0)]=1
ans=0
for i in range(N):
    cntc=cnt.copy()
    dpc=dp.copy()
    for j in range(B):
        if dpc[j]+V[i]>=dpc[j+1]:
            dp[j+1]=dpc[j]+V[i]
            cnt[(j+1,dp[j+1])]+=cntc[(j,dpc[j])]
            if j+1>=A:
                ans=max(ans,dp[j+1]/(j+1))
res=0 
for i in range(A,B+1):
    res+=cnt[(i,int(ans*i))]
print(ans)
print(res)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
inf=float('inf')
dp=[-1*inf]*(B+1)
dp[0]=0
from collections import defaultdict
cnt=defaultdict(int)
cnt[(0,0)]=1
ans=0
for i in range(N):
    cntc=cnt.copy()
    dpc=dp.copy()
    for j in range(B):
        if dpc[j]+V[i]>=dpc[j+1]:
            dp[j+1]=dpc[j]+V[i]
            cnt[(j+1,dp[j+1])]+=cntc[(j,dpc[j])]
            if j+1>=A:
                ans=max(ans,dp[j+1]/(j+1))
res=0 
for i in range(A,B+1):
    res+=cnt[(i,ans*i)]
print(ans)
print(res)

Submission status: Wrong Answer

Solution code:
import numpy

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

v.sort()

res = numpy.average(v[n - a:])
x = min(v[n - a:])

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

if v[n - 1] != x:
    print(res)
    c = v[:n - a].count(x)
    m = v.count(x)
    print(cmb(m, m - c))
else:
    print(res)
    ans = 0
    for i in range(a, b + 1):
        ans += cmb(n, i)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

v.sort()

res = numpy.average(v[n - a:])
x = min(v[n - a:])

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

if res > int(res) or int(res) > x:
    print(res)
    c = v[:n - a].count(x)
    m = v.count(x)
    print(cmb(m, m - c))
else:
    #print("hoge")
    print(res)
    c = v[:n-a].count(int(res))
    m = v.count(int(res))
    temp = cmb(m, m - c)
    ans = temp
    for i in range(m - c + 1, m - c + c + 1):
        #print(ans)
        ans += cmb(m, i)
    print(ans)

Submission status: Wrong Answer

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

v.sort(reverse=True)

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

p = v[A-1]
q = v.count(p)
r = v.index(p)
ans2=0
if not N == q:
    #q P A-r
    ans2 = math.factorial(q) // math.factorial(q+r-A) // math.factorial(A-r)
else: # N==q
    for i in range(A,B+1):
        # q P i
        ans2 += math.factorial(q) // math.factorial(q-i) // math.factorial(i)
print(ans2)

Submission status: Wrong Answer

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

v.sort(reverse=True)

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

p = v[A-1]
q = v.count(p)
r = v.index(p)
ans2=0
if not N == q:
    #q P A-r
    ans2 = math.factorial(q) // math.factorial(q+r-A) // math.factorial(A-r)
else: # N==q
    for i in range(N):
        # q P i
        ans2 += math.factorial(q) // math.factorial(q-i) // math.factorial(i)
print(ans2)

Submission status: Wrong Answer

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

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=V.count(V[A-1])
print(ans)

Submission status: Wrong Answer

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

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=V.count(V[A])
print(ans)

Submission status: Wrong Answer

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

def fac(n):
  if n== 1: return 1
  if n==0: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[A]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[A])+1)):
    ans+=c(V.count(V[A]),i)
else:
  ans=V.count(V[A])
print(ans)

Submission status: Wrong Answer

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

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

def c(a,b):
    if b == 0: return 1
    tmp = fac[a]
    for i in range(1,b+1):
        tmp //= i
    for i in range(1, a-b+1):
        tmp //= i
    return tmp 

ctr = Counter(V)

ans1 = 0
ncnt = 0
bA = A
lst = 0

for v in V:
    tmp = ans1
    if (tmp*ncnt+v)/(ncnt+1) > ans1 or A:
        ans1 = (tmp*ncnt+v)/(ncnt+1)
        ncnt += 1
        A -= 1
        lst = v

if V[0] != lst:
    print(ans1)
    print(ctr[lst])

if V[0] == lst:
    print(ans1)
    ans2 = 0
    for ia in range(bA, B+1):
        if ia >= ctr[lst]+1: break
        ans2 += c(ctr[lst], ia)
    print(ans2)

Submission status: Wrong Answer

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

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

def c(a,b):
    if b == 0: return 1
    tmp = fac[a]
    for i in range(1,b+1):
        tmp //= i
    for i in range(1, a-b+1):
        tmp //= i
    return tmp 

ctr = Counter(V)

ans1 = 0
ncnt = 0
bA = A
lst = 0

for v in V:
    tmp = ans1
    if (tmp+v)/(ncnt+1) > ans1 or A:
        ans1 = (tmp+v)/(ncnt+1)
        ncnt += 1
        A -= 1
        lst = v

if V[0] != lst:
    print(ans1)
    print(ctr[lst])

if V[0] == lst:
    print(ans1)
    ans2 = 0
    for ia in range(bA, B+1):
        if ia >= ctr[lst]+1: break
        ans2 += c(ctr[lst], ia)
    print(ans2)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
def f(x,y):
    c=1
    d=1
    for i in range(x):
        c*=(i+1)
        d*=(y-i)
    return d//c
p=v[n-a:]
g=sum(p)/a
w=0
for i in range(a,b+1):
    p=v[n-i:]
    h=sum(p)/i
    if h<g:
        break
    else:
        q=p[0]
        d=v.count(q)
        e=p.count(q)
        w+=f(e,d)
print(w)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
p=v[n-a:]
print(sum(p)/a)
q=p[0]
d=v.count(q)
e=p.count(q)
c=1
d=1
for i in range(e):
    c*=(i+1)
    d*=(e-i)
print(d//c)

Submission status: Wrong Answer

Solution code:
import bisect
from math import factorial
def comb_cnt(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

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

maxsum = sum(vs[-a:])
val = vs[-a]
l, r = bisect.bisect_left(vs, val), bisect.bisect_right(vs, val)
nmin, nmax = r - (n - a), r - max(l, n - b)
print(a, b, l, r, nmin, nmax)
if r != n:
    ans = comb_cnt(r - l, nmin)
else:
    ans = 0
    for i in range(nmin, nmax + 1):
        ans += comb_cnt(r - l, i)

print(maxsum / a)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math 
N,A,B = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
print(sum(x[-A:])/A)
c = collections.Counter(x)
s=0
ans=0
for i in range(N-1,0,-1):
    t = s
    s+=c.get(x[i])
    if s>=A and t ==0:
        #print(c.get(x[i]))
        for j in range(A,min(c.get(x[i]),B)+1):
            #print(ans)
            ans+=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-j)*math.factorial(j))
        break
    elif s>=A:
        ans+=math.factorial(c.get(x[i]))/math.factorial(c.get(x[i])-(A-t))*math.factorial(A-t)
        break
print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections
import math 
N,A,B = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
print(sum(x[-A:])/A)
c = collections.Counter(x)
s=0
ans=0
for i in range(N-1,0,-1):
    t = s
    s+=c.get(x[i])
    if s>=A and t ==0:
        #print(c.get(x[i]))
        for j in range(A,min(c.get(x[i]),B)+1):
            #print(ans)
            ans+=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-j)*math.factorial(j))
        break
    elif s>=A:
        ans+=math.factorial(c.get(x[i]))/math.factorial(c.get(x[i])-(A-t))*math.factorial(A-t)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    c = v_count[v[A-1]]
    for i in range(min(B-A, c)):
        ans += comb(c,i)
else:
    c = v_count[v[A-1]]
    select_count = Counter(v[:A])
    need = select_count[v[A-1]]
    for i in range(need, min(need+B-A, c)):
        ans += comb(c,i)
    if need==min(need+B-A, c): ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    c = v_count[v[A-1]]
    for i in range(min(B-A, c)):
        ans += comb(c,i)
else:
    c = v_count[v[A-1]]
    select_count = Counter(v[:A])
    need = select_count[v[A-1]]
    #print(c, need)
    for i in range(need, min(need+B-A, c)+1):
        ans += comb(c,i)
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_max = max(v_arr)
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

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

def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return factorial[n] / (factorial[k] * factorial[n - k])

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    p_prev = p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
ans = 0
if p == v_max:
    for i in range(min(last_count_all, B) - last_count + 1):
        ans += combination(last_count_all, last_count + i)
else:
    ans = combination(last_count_all, last_count)
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

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

def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return factorial[n] / (factorial[k] * factorial[n - k])

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    p_prev = p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
ans = 0
if last_count == A:
    for i in range(B - A + 1):
        ans += combination(last_count_all, last_count + i)
else:
    ans = combination(last_count_all, last_count)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
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.sort(reverse=True)
counter = OrderedDict()
for i in range(N):
    if v[i] in counter:
        counter[v[i]][0] += 1
    else:
        counter[v[i]] = [1, i + 1]
average = []
for i in range(A, B + 1):
    ave = sum(v[:i]) / i
    num = comb(counter[v[i - 1]][0], i - counter[v[i - 1]][1] + 1)
    average.append([ave, num])
average.sort(key=lambda x: -x[0])
M_arv = average[0][0]
ans = 0
for item in average:
    if item[0] == M_arv:
        ans += item[1]
    else:
        break
print('{:.6f}'.format(M_arv))
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy
from bisect import bisect_left
from math import factorial
n, a, b = map(int, input().split())
vs = list(map(int, input().split()))

vs.sort(reverse=True)

prev = None
cnt = 0
kosu = []
ruiseki_kosu = []
for v in vs:
    if prev is None:
        prev = v
    if prev == v:
        cnt += 1
    else:
        kosu.append(cnt)
        if len(ruiseki_kosu):
            ruiseki_kosu.append(ruiseki_kosu[-1]+cnt)
        else:
            ruiseki_kosu.append(cnt)
        cnt = 1
        prev = v
kosu.append(cnt)
if len(ruiseki_kosu):
    ruiseki_kosu.append(ruiseki_kosu[-1]+cnt)
else:
    ruiseki_kosu.append(cnt)
ruiseki_kosu = [i -1 for i in ruiseki_kosu]

ruiseki = numpy.cumsum(vs)
ans = []
for k in range(a-1,b):
    average = ruiseki[k]/(k+1)
    ind = bisect_left(ruiseki_kosu, k)
    cnt = ruiseki_kosu[ind]
    left = kosu[ind]
    right = cnt - k
    ck = factorial(left)//(factorial(left-right)*factorial(right))
    ans.append([average, ck])
ans.sort(reverse=True)

max_ = ans[0][0]
hoge = 0
for ave, cnt in ans:
    if ave == max_:
        hoge += cnt
    else:
        break
print(max_)
print(hoge)

Submission status: Wrong Answer

Solution code:
import numpy
from bisect import bisect_left
from math import factorial
n, a, b = map(int, input().split())
vs = list(map(int, input().split()))

vs.sort(reverse=True)

prev = None
cnt = 0
kosu = []
ruiseki_kosu = []
for v in vs:
    if prev is None:
        prev = v
    if prev == v:
        cnt += 1
    else:
        kosu.append(cnt)
        if len(ruiseki_kosu):
            ruiseki_kosu.append(ruiseki_kosu[-1]+cnt)
        else:
            ruiseki_kosu.append(cnt)
        cnt = 1
        prev = v
kosu.append(cnt)
if len(ruiseki_kosu):
    ruiseki_kosu.append(ruiseki_kosu[-1]+cnt)
else:
    ruiseki_kosu.append(cnt)
ruiseki_kosu = [i -1 for i in ruiseki_kosu]

ruiseki = numpy.cumsum(vs)
ans = []
for k in range(a-1,b):
    average = ruiseki[k]/(k+1)
    ind = bisect_left(ruiseki_kosu, k)
    cnt = ruiseki_kosu[ind]
    left = kosu[ind]
    right = cnt - k
    ck = factorial(left)//(factorial(left-right)*factorial(right))
    ans.append([average, ck])
ans.sort(reverse=True)

max_ = ans[0][0]
hoge = 0
for ave, cnt in ans:
    if ave == max_:
        hoge += cnt
    else:
        break
print(hoge)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

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

def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return factorial[n] / (factorial[k] * factorial[n - k])

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
ans = 0
if last_count == A:
    for i in range(B - A + 1):
        ans += combination(last_count_all, last_count + i)
else:
    ans = combination(last_count_all, last_count)
print(ans)

Submission status: Wrong Answer

Solution code:
def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return combination(n-1, k) + combination(n-1, k-1)

N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
ans = 0
for i in range(B - A):
    ans += combination(last_count_all, last_count + i)
print(ans)

Submission status: Wrong Answer

Solution code:
def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    else:
        return combination(n-1, k) + combination(n-1, k-1)

N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
print(combination(last_count_all, last_count))

Submission status: Wrong Answer

Solution code:
import itertools

N, A, B = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 0
ind = 0

for i in range(A, B+1):
    num = list(itertools.combinations(v, i))
    for x in num:
        if ans <= sum(x) / i:
            ind = i
            ans = sum(x) / i

print(ans)
print(ind)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


n, a, b = LI()
V = LI()
V.sort()
V.reverse()

cnt = defaultdict(int)
sum_v = 0
for i in range(a):
    sum_v += V[i]
    cnt[V[i]] += 1

# 大きい順にa個選ぶ場合，価値の平均値は最大となる
print(sum_v / a)

# a個選んだ中で一番価値の低いものがいくつ残っているか数える
min_v = V[i]
min_cnt = cnt[min_v]
for i in range(a, n):
    v = V[i]
    if v != min_v:
        break
    cnt[v] += 1

if cnt[min_v] == min_cnt:
    print(1)
    exit()
elif len(cnt.keys()) != 1:
    print(comb(cnt[min_v], min_cnt))
    exit()
ans = 0
for i in range(b - a + 1):
    ans += comb(cnt[min_v], min_cnt + i)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            if all_counter[fv] <= B:
                ans *= (2 ** all_counter[fv] ) - 1
            else:
                ts = 0
                for c in range(A, B+1):
                    ts += factorial(all_counter[fv]) // factorial(c) // factorial(all_counter[fv]-c)
                ans *= ts
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])

if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            if all_counter[fv] <= B:
                ans *= (2 ** all_counter[fv] ) - 1
            else:
                ts = 0
                for c in range(1, B+1):
                    ts += factorial(all_counter[fv]) // factorial(c) // factorial(all_counter[fv]-c)
                ans *= ts
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])

if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            ans *= (2 ** min(all_counter[fv], B)) - 1
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])

if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            ans *= (2 ** all_counter[fv]) - 1
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])


if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter
from math import factorial

def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    return factorial(n) / factorial(r) / factorial(n-r)

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

# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値が欲しいので降順ソートしておく
vN.sort(reverse=True)

mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
    avg = sum(vN[:i]) / i
    if avg == mx_avg:
        # 平均値が最大になるなら、選び方リストに追加
        lists.append(vN[:i])

ans = 0
for l in lists:
    # 選び方を、同じ値の個数毎にまとめる
    c2 = Counter(l)
    combs = 1
    for k, v in c2.items():
        # 同じ値が複数ある場合の組み合わせを出す
        combs *= nCr(c[k], v)
    ans += combs
print(mx_avg)
print(int(ans))

Submission status: Wrong Answer

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

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def comb(n, r):
    r = min(r, n-r)
    ret = 1
    for i in range(r+1):
        ret *= (n-i)/(i+1)
    return ret


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Submission status: Wrong Answer

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

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def comb(n, r):
    r = min(r, n-r)
    ret = 1
    for i in range(r+1):
        ret *= (n-i)/(i+1)
    return ret


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print(ans)

Submission status: Wrong Answer

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

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    return c[last]


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b,*v=map(int,open(0).read().split())
v=[0]+v
dp=[[[0,1]for j in range(b+1)]for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,b+1):
    if dp[i-1][j-1][0]+v[i]>dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j-1][0]+v[i],1]
    elif dp[i-1][j-1][0]+v[i]==dp[i-1][j][0]:
      dp[i][j]=dp[i-1][j]
      dp[i][j][1]+=1
    else:
      dp[i][j]=dp[i-1][j]
m=0
for i in range(a,b+1):
  m=max(m,dp[-1][i][0]/i)
print(m,sum(dp[-1][i][1]*(dp[-1][i][0]/i==m)for i in range(a,b+1)),sep='\n')

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)

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

V_Ath = V[A - 1]
V_Ath_CNT = V.count(V_Ath)

if max(V) == V_Ath:
    for n in range(A, B + 1):
        ans2 += comb(V_Ath_CNT, n, 1)
else:
    ans2 = V.count(V_Ath)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


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

mean_max = 0
comb = 0
first = -1
for i in range(A, B + 1):
    sum_num = sum(v_list[:i])
    if mean_max * i == sum_num and v_list[i:].count(min(v_list[:i])) >= 1:
        comb += combination(v_list.count(min(v_list[:i])), v_list[i:].count(min(v_list[i:])))
    if mean_max * i < sum_num:
        mean_max = sum_num / i
        first = i
if first != -1 and v_list[first:].count(min(v_list[:first])) >= 1:
    comb += combination(v_list.count(min(v_list[:first])), v_list[first:].count(min(v_list[first:])))
print(mean_max)
print(comb if comb != 0 else 1)

Submission status: Wrong Answer

Solution code:
def combination(n, r):  # nCrを求める
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
ans1 = 0
ans2 = 0
count = 1
j = 0
for i in range(a,b+1):
    p = sum(v[:i])/i
    if ans1 < p:
        ans1 = p
        j = i
        count = 1
    elif ans1 == p:
        count += 1
print(ans1)
q =v.count(v[j])
for i in range(1,count+1):
    ans2 += combination(q,i)
print(ans2)

Submission status: Wrong Answer

Solution code:
def nCr(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

N, A, B = map(int, input().split())
nums = list(map(int, input().split()))
ave = 0
num = 0
j = N - A

nums.sort()
for i in range(A):
    ave += nums[N - i - 1]
ave = ave/A

if nums[j] == nums[N-1]:
    re = nums.count(nums[j])
    c = min(re, B+1)
    for i in range(A, c+1):
        num = num + nCr(re, i)
else:    
    num = nums.count(nums[j])
    
print(ave)    
print(int(num))

Submission status: Wrong Answer

Solution code:
import math
N, A, B = map(int, input().split())
nums = list(map(int, input().split()))
ave = 0
num = 0
j = N - A

nums.sort()
for i in range(A):
    ave += nums[N - i - 1]
ave = ave/A

if nums[j] == nums[N-1]:
    re = nums.count(nums[j])
    c = min(re, B+1)
    for i in range(A, c+1):
        num = num + math.factorial(re) / math.factorial(i) / math.factorial(re-i)
else:    
    num = nums.count(nums[j])
    
print(ave)    
print(int(num))