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:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        elif v>b:
            for i in range(a,b):
                value+=k*i
                cnt+=i
                nn=v
                kk=i
                ans+=comb(nn, kk)
            break              
        elif v<=b:
            for i in range(a,v):
                value+=k*i
                cnt+=i
                nn=v
                kk=i
                ans+=comb(nn, kk)
            break 
if one_flg:
    ans=1
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        elif v>=b:
            for i in range(a,b):
                value+=k*i
                cnt+=i
                nn=v
                kk=i
                ans+=comb(nn, kk)
            break              

if one_flg:
    ans=1
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        elif v==b and b!=0:
            print(k)
            print(2**b-1)
            exit()
        elif v>=b:
            for i in range(a,b):
                value+=k*i
                cnt+=i
                nn=v
                kk=i
                ans+=comb(nn, kk)
            break              

if one_flg:
    ans=1
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V = list(map(int, input().split()))

V.sort(reverse=True)

c = Counter(V)
# V[:A] は 逆順にA個取り出す
print("V[:A]", V[:A])
max_average = sum(V[:A]) / A
print("max_average", max_average)
# それぞれの要素の個数
c_max = Counter(V[:A])
print("c_max", c_max)

# 組み合わせ
def nCr(n,r):
    if n < 0 or r < 0 or n < r: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
  
    # 分子のn*(n-1)*...がr個分続くやつ
    numerator = [n-r+k+1 for k in range(r)]
    # 分母：r!=r*(r-1)*...*3*2の要素
    denominator = [k+1 for k in range(r)]
  
    # 分母の要素で割れる部分を割っていく部分
    for p in range(2, r+1):
        # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
        pivot = denominator[p-1]
        if pivot > 1:
          # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
            offset = (n-r) % p
            for k in range(p-1, r, p):
                # 約分できる要素について割る
                numerator[k - offset]  /= pivot
                denominator[k] /= pivot
        
    ret = 1
    for k in range(r):
        if numerator[k] > 1: ret *= int(numerator[k])
      
    return ret

# A個選んだ時の最大平均値が、全て同じ価値で構成されている時
# この場合は、全体の個数の取り方が、A〜min(B, V_maxの個数)と、複数ある
if len(c_max) == 1:
    # A個選ぶ、A+1個選ぶ、...、min(B, c[V[0]])個選ぶ　の和が答え
    ans = 0
    n = c[V[0]]
    for r in range(A, min(B, n)+1):
        ans += nCr(n,r)


# 最大平均値が複数の価値から作られる場合、価値が大きい順から全て使われる価値がいくつかと、中途半端に使われる価値が一つになる
# なので、中途半端に選ばれるものの選び方を数え上げる
# この時、全体の個数はA個固定（さらに何かを追加すると平均が減少するため）
else:
    
    # 最大平均値を構成する、最小の価値を探す
    tmp = list(c_max.keys())
    tmp.sort()
    # 最小の値
    min_num = tmp[0]
    # 最小以外の数字で何個選んでいるか
    cnt = 0
    for i in tmp[1:]:
        cnt += c_max[i]
    remaining = A - cnt

    ans = nCr(c[min_num], remaining)

print(max_average)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
    elif a<v:
        value+=k*a
        cnt+=a
        nn=v
        kk=a
        ans=comb(nn, kk)
        break
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**n-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
    elif a<v:
        value+=k*a
        cnt+=a
        nn=v
        kk=a
        ans=comb(nn, kk)
        break
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
sm=sum(v[-a:])
av=sm/a
ky=v[-a]
c=v.count(ky)
co=0
for i in range(n):
    if v[-i-1]>ky:
        co+=1
ans=0
#print(v)
if co>0:
    ans=cmb(c,a-co)
else:
    for i in range(a,min(b+1,c+co+1)):
        ans+=cmb(c,i-co)
#print(av)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    #こっちが間違ってる
    m=min(v[0][1],B)
    co=2**m
    for i in range(A):
        co-=combinations_count(m,i)
    print(float(v[0][0]))
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    #こっちが間違ってる
    m=min(v[0][1],B)
    co=2**m
    for i in range(A):
        co-=combinations_count(m,i)
    print(A*v[0][0]/A)
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    m=min(v[0][1],B)
    co=2**m
    for i in range(A):
        co-=combinations_count(m,i)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    m=min(v[0][1],B)
    co=(2**m-2**(A-1))
    #print(m-A)
    #for i in range(A,m+1):
    #    co+=combinations_count(m,i)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

n,A,B=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
v=groupby(v)

if A<=v[0][1]:
    m=min(v[0][1],B)
    co=0
    #print(m-A)
    for i in range(A,m+1):
        co+=combinations_count(m,i)
        #co+=comb(m,A,exact=True)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
            #k=comb(v[i][1],B,exact=True)
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

n,A,B=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
v=groupby(v)

if A<=v[0][1]:
    m=min(v[0][1],B)
    co=0
    #print(m-A)
    for i in range(A,m+1):
        co+=combinations_count(m,i)
        #co+=comb(m,A,exact=True)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
            #k=comb(v[i][1],B,exact=True)
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

n,A,B=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
v=groupby(v)
if A<=v[0][1]:
    m=min(v[0][1],B)
    co=0
    #print(m-A)
    for i in range(A,m+1):
        co+=combinations_count(m,i)
        #co+=comb(m,A,exact=True)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    B=A
    k=1
    for i in range(l):
        B-=v[i][1]
        if B>=0:
            al+=(v[i][0]*v[i][1])
        else:
            B+=v[i][1]
            al+=(v[i][0]*B)
            k=combinations_count(v[i][1],B)
            #k=comb(v[i][1],B,exact=True)
    print(al/A)
    print(k)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int,input().split())
V = list(map(int,input().split()))
V.sort(reverse = True)
Vs=V[:A]
print(sum(Vs)/A)
###################################
Vl = list(set(Vs))
Vl.sort(reverse = True)
n = len(Vl)
C = [V.count(Vl[_]) for _ in range(n)]
###################################
def Per(L):
    ret = 1
    for i in L:
        ret *= i
    return ret
###################################
com = [[0]*51 for i in range(51)]
for i in range(51):
    com[i][0] = 1
    for j in range(1, 51):
        com[i][j] = com[i-1][j-1] + com[i-1][j]
###################################
if n!=1:
    ans = Per(C)
else:
    ans = 0
    for k in range(A,B+1):
        ans += com[C[0]][k]
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)
Vs=V[:A]
print(sum(Vs)/A)
###################################
Vl = list(set(Vs))
Vl.sort(reverse = True)
n = len(Vl)
C = [V.count(Vl[_]) for _ in range(n)]
###################################
def Per(L):
    ret = 1
    for i in L:
        ret *= i
    return ret
###################################
def Com(n,k):
    if k == 0:
        return 1
    else:
        return Com(n,k-1)*(n-k+1)//k
###################################
if n!=1:
    ans = Per(C)
else:
    ans = 0
    for k in range(A,B+1):
        ans += Com(C[0],k)
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int,input().split())
V = list(map(int,input().split()))
Vl = list(set(V))
Vl.sort(reverse = True)
C = []
sumC = 0
av = 0
for v in Vl:
  cnt = V.count(v)
  C.append(cnt)
  cnt = min(cnt, A-sumC)
  av += v * cnt
  sumC += cnt
  if sumC == A:
    break
if len(C)!=1:
  P = 1
  for i in C:
      P = P * i
else:
  Q = 1
  P = 0
  for k in range(1,B+1):
    Q = (Q*(C[0]-k+1))//k
    if A<=k<=B:
      P += Q
print(av/A)
print(P)

Submission status: Wrong Answer

Solution code:
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]-1):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[-1]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
ans=0
if vmin[0]!=vmin[-1]:
    ans=f(mini+ex)//(f(mini)*f(ex))
    print(ans)
else:
    m=min(nab[2]-nab[1],ex)
    for i in range(m+1):
        ans+=f(mini+m)//(f(mini+i)*f(m-i))
    print(ans)

Submission status: Wrong Answer

Solution code:
#  Copyright: this code was written at 2020. for AtCoder by Silviase


def make_pascal_tri(n):
    array = [[1 for i in range(n + 1)] for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(n + 1):
            if j > i:
                array[i][j] = 0
            elif j == 0 or j == i:
                array[i][j] = 1
            else:
                array[i][j] = array[i - 1][j] + array[i - 1][j - 1]
    return array


ar = make_pascal_tri(100)
n, a, b = map(int, input().split())
val = sorted(map(int, input().split()), reverse=True)
res_ave = 0
for i in range(a):
    res_ave += val[i]
res_ave /= a
grat_cnt = 0
same_cnt = 0
for i in range(n):
    if val[i] > val[a - 1]:
        grat_cnt += 1
    elif val[i] == val[a - 1]:
        same_cnt += 1
    else:
        break
result = 0
if grat_cnt == 0:
    for i in range(a, min(same_cnt + 1, b + 1)):
        result = ar[same_cnt][i]
else:
    result = ar[same_cnt][a - grat_cnt]

print(res_ave)
print(result)

Submission status: Wrong Answer

Solution code:
#  Copyright: this code was written at 2020. for AtCoder by Silviase


def make_pascal_tri(n):
    array = [[1 for i in range(n + 1)] for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(n + 1):
            if j > i:
                array[i][j] = 0
            elif j == 0 or j == i:
                array[i][j] = 1
            else:
                array[i][j] = array[i - 1][j] + array[i - 1][j - 1]
    return array


ar = make_pascal_tri(100)
n, a, b = map(int, input().split())
val = sorted(map(int, input().split()), reverse=True)
res_ave = 0
for i in range(a):
    res_ave += val[i]
res_ave /= a
grat_cnt = 0
same_cnt = 0
for i in range(b):
    if val[i] > val[a - 1]:
        grat_cnt += 1
    elif val[i] == val[a - 1]:
        same_cnt += 1
    else:
        break
result = 0
if grat_cnt == 0:
    for i in range(a, same_cnt + 1):
        result = ar[same_cnt][i]
else:
    result = ar[same_cnt][a - grat_cnt]

print(res_ave)
print(result)

Submission status: Wrong Answer

Solution code:
#  Copyright: this code was written at 2020. for AtCoder by Silviase


def make_pascal_tri(n):
    array = [[1 for i in range(n + 1)] for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(n + 1):
            if j > i:
                array[i][j] = 0
            elif j == 0 or j == i:
                array[i][j] = 1
            else:
                array[i][j] = array[i - 1][j] + array[i - 1][j - 1]
    return array


ar = make_pascal_tri(100)
n, a, b = map(int, input().split())
val = sorted(map(int, input().split()), reverse=True)
res_ave = 0
for i in range(a):
    res_ave += val[i]
res_ave /= a
grat_cnt = 0
same_cnt = 0
for i in range(b):
    if val[i] > val[a - 1]:
        grat_cnt += 1
    elif val[i] == val[a - 1]:
        same_cnt += 1
    else:
        break
result = 0
for i in range(a - grat_cnt, grat_cnt + same_cnt + 1):
    result += ar[same_cnt][i]
print(res_ave)
print(result)

Submission status: Wrong Answer

Solution code:
#  Copyright: this code was written at 2020. for AtCoder by Silviase


def make_pascal_tri(n):
    array = [[1 for i in range(n + 1)] for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(n + 1):
            if j > i:
                array[i][j] = 0
            elif j == 0 or j == i:
                array[i][j] = 1
            else:
                array[i][j] = array[i - 1][j] + array[i - 1][j - 1]
    return array


ar = make_pascal_tri(100)
n, a, b = map(int, input().split())
val = sorted(map(int, input().split()), reverse=True)
res_ave = 0
for i in range(a):
    res_ave += val[i]
res_ave /= a
grat_cnt = 0
same_cnt = 0
for i in range(b):
    if val[i] > val[a - 1]:
        grat_cnt += 1
    elif val[i] == val[a - 1]:
        same_cnt += 1
    else:
        break
result = 0
for i in range(a - grat_cnt, grat_cnt + same_cnt + 1):
    result += ar[same_cnt][i]
print(result)

Submission status: Wrong Answer

Solution code:
#57d
from bisect import bisect_left, bisect_right
from scipy.misc import comb

N,A,B = map(int, input().split())
v_list = [int(e) for e in input().split()]

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

min_value = v_list[A-1]

v_list.sort(reverse=False)
min_value_left = bisect_left(v_list, min_value)
min_value_right = bisect_right(v_list, min_value)

duplicated = min_value_right - min_value_left #最小値の重複個数
fixed = N - min_value_right #固定されている個数

ans = 0

#print(fixed)
#print(duplicated)

min_choice = max(1,A - fixed)
if fixed==0:
    max_choice = B + 1
else:
    max_choice = B - fixed

if min_choice != max_choice:
    for i in range(min_choice,max_choice):
        ans += comb(duplicated, i, exact=True)
else:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
def ncr(x,y):
	ans=1
	q=x-y
	while x>y:
		ans*=x
		x=x-1
	
	while q>1:
		ans=ans/q
		q=q-1
	
	return ans

x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=[0]*n
x = input().split()
ind=0
M={1:0}
M2={1:0}
for i in x:
	v[ind]=int(i)
	if int(i) in M:
		M[v[ind]]+=1
	else:
		M[v[ind]]=1
	ind+=1
v.sort(reverse=True)

cnt=0
ind=0
m=0
while cnt<a:
	cnt+=1
	m=((cnt-1)*m+v[ind])/cnt
	if v[ind] in M2:
		M2[v[ind]]+=1
	else:
		M2[v[ind]]=1
	ind+=1
while cnt<b:
	if (cnt*m+v[ind])/(cnt+1)<m-0.5:
		break
	else:
		cnt+=1;
		if v[ind] in M2:
			M2[v[ind]]+=1
		else:
			M2[v[ind]]=1
		ind+=1
print(m)
maxw=cnt;
ways=0;
for i in range(cnt,a-1,-1):
	if v[ind-1] not in M2:
			M2[v[ind]]=0
	if v[ind-1] not in M:
			M[v[ind-1]]=0
	ways+=ncr(M[v[ind-1]],M2[v[ind-1]])
	
	M2[v[ind-1]]-=1

print(int(ways))

Submission status: Wrong Answer

Solution code:
def ncr(x,y):
	ans=1
	q=x-y
	while x>y:
		ans*=x
		x=x-1
	
	while q>1:
		ans=ans/q
		q=q-1
	
	return ans

x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=[0]*n
x = input().split()
ind=0
M={1:0}
M2={1:0}
for i in x:
	v[ind]=int(i)
	if int(i) in M:
		M[v[ind]]+=1
	else:
		M[v[ind]]=1
	ind+=1
v.sort(reverse=True)

cnt=0
ind=0
m=0
while cnt<a:
	cnt+=1
	m=((cnt-1)*m+v[ind])/cnt
	if v[ind] in M2:
		M2[v[ind]]+=1
	else:
		M2[v[ind]]=1
	ind+=1
while cnt<b:
	if (cnt*m+v[ind])/(cnt+1)<m:
		break
	else:
		cnt+=1;
		m=((cnt-1)*m+v[ind])/cnt
		if v[ind] in M2:
			M2[v[ind]]+=1
		else:
			M2[v[ind]]=1
		ind+=1
print(m)
maxw=cnt;
ways=0;
for i in range(cnt,a-1,-1):
	if v[ind-1] not in M2:
			M2[v[ind]]=0
	if v[ind-1] not in M:
			M[v[ind-1]]=0
	ways+=ncr(M[v[ind-1]],M2[v[ind-1]])
	
	M2[v[ind-1]]-=1

print(int(ways))

Submission status: Wrong Answer

Solution code:
from math import factorial
import bisect
def cmb(n,r):
  if n<0 or r<0:
    return 0
  else:
    return factorial(n)//factorial(n-r)//factorial(r)
n,a,b=map(int,input().split())
x = list(map(int,input().split()))
ans=0
x.sort(reverse=True)
print(sum(x[:a])/a)
if n==a:
  print(1)
elif x[0]==x[a]:
  for i in range(n):
    if x[0] != x[i]:
      k=i
      break
  else:
    k=n
  for i in range(a,min(k,b+1)):
    ans+=cmb(k,i)
  print(ans)
elif x[a-1] == x[a]:
  y=sorted(x)
  x1=bisect.bisect_left(y,x[a])
  x2=bisect.bisect_right(y,x[a])
  print(cmb(x2-x1,a-(n-x2)))
else:
  print(1)

Submission status: Wrong Answer

Solution code:

def combination_table(N):
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(i):
            if j==0 or j==i:
                C[i][j]=1
            else:
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    return C[2:]

if __name__ == '__main__':
    N,A,B=list(map(int,input().split()))
    V=list(map(int,input().split()))
    V.sort(reverse=True)

    temp=V[:A]
    max_mean=sum(temp)/A
    count=0

    C=combination_table(N+2)


    if V[0]!=V[A-1]:
        count=1
        for i in range(A):
            temp_1=V.count(V[i])
            count*=temp_1
        """temp_1=V.count(V[0])
        temp_2=V[:A].count(V[0])
        count+=C[temp_1-1][temp_2]"""
    elif V[0]==V[A-1]:
        for i in range(A,B+1):
            temp_1=V.count(V[0])
            count+=C[temp_1-1][i]

    print(max_mean)
    print(count)

Submission status: Wrong Answer

Solution code:

def combination_table(N):
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(i):
            if j==0 or j==i:
                C[i][j]=1
            else:
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    return C[2:]

if __name__ == '__main__':
    N,A,B=list(map(int,input().split()))
    V=list(map(int,input().split()))
    V.sort(reverse=True)

    temp=V[:A]
    max_mean=sum(temp)/A
    count=0

    C=combination_table(N+2)


    if V[0]!=V[A-1]:
        temp_1=V.count(V[0])
        temp_2=V[:A].count(V[0])
        count+=C[temp_1-1][temp_2]
    elif V[0]==V[A-1]:
        for i in range(A,B+1):
            temp_1=V.count(V[0])
            count+=C[temp_1-1][i]

    print(max_mean)
    print(count)

Submission status: Wrong Answer

Solution code:

def combination_table(N):
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(i):
            if j==0 or j==i:
                C[i][j]=1
            else:
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    return C[2:]

if __name__ == '__main__':
    N,A,B=list(map(int,input().split()))
    V=list(map(int,input().split()))
    V.sort(reverse=True)

    temp=V[:A]
    max_mean=sum(temp)/A
    count=0

    C=combination_table(N+2)


    if V[0]!=V[A-1]:
        temp_1=V.count(V[0])
        temp_2=V[:A].count(V[0])
        count+=C[temp_1][temp_2]
    elif V[0]==V[A-1]:
        for i in range(A,B+1):
            temp_1=V.count(V[0])
            count+=C[temp_1-1][i]

    print(max_mean)
    print(count)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(sum([factorial(n) // factorial(r) // factorial(n - r)
               for r in range(A, n + 1)]))
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    if list(ac([v-m for v in V]))[A-1] >= 0:
        l = m
    else:
        r = m

fa = [1]
for i in range(1, 60):
    fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(l/t)
print(V.count(V[A-1]) if V[0] > l else sum([C(V.count(l), i) for i in range(A, B+1)]))

Submission status: Wrong Answer

Solution code:
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    VV = [v-m for v in V]
    for i in range(1, len(VV)):
        VV[i] += VV[i-1]
    if max(VV[A-1:B]) >= 0:
        l = m
    else:
        r = m

print(l/t)
print(V.count(V[B-1]) if V[B-1] > l else V.count(V[A-1]) if V[A-1] < l else 1 << V.count(l))

Submission status: Wrong Answer

Solution code:
t = 3099044504245996706400
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<100
while r - l > 1:
    m = (l+r) // 2
    VV = [v-m for v in V]
    for i in range(1, len(VV)): VV[i] += VV[i-1]
    if max(VV[A-1:B]) >= 0: l = m
    else: r = m

print(l/t)
print(sum([sum([V[j] * (i>>j & 1) for j in range(N)]) == l * bin(i).count("1") for i in range(1, 1<<N)]))

Submission status: Wrong Answer

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

v = sorted(v)[::-1]

def C(x):
    s = 0
    for i in range(n):
        s += v[i] - x
        if a-1 <= i and i <= b-1 and s >= 0:
            return True
    return False

lb = 0
ub = 10 ** 15 + 1
for i in range(10 ** 6):
    mid = (lb + ub) / 2
    if C(mid):
        lb = mid
    else:
        ub = mid
print(lb)

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

ans = 0
from collections import Counter
c0 = Counter(v)

s = v[:a-1]
s_tot = sum(s)
c = Counter(s)
for k in range(a, b+1):
    tot = lb * k

    s.append(v[k-1])
    s_tot += v[k-1]
    c[v[k-1]] += 1
    if s_tot == tot:
        tmp = 1
        for key in c.keys():
            tmp *= combs(c0[key], c[key])
        ans += tmp
print(ans)