Problem:


Score : 400 points

Problem Statement

You are given N items.

The value of the i-th item (1 \leq i \leq N) is v_i.

Your have to select at least A and at most B of these items.

Under this condition, find the maximum possible arithmetic mean of the values of selected items.

Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.  

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

The input is given from Standard Input in the following format:

N A B
v_1
v_2
...
v_N

Output

Print two lines.

The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.

The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.

There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

There can be multiple ways to select items so that the mean of the values will be maximized.

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1



Sample input:
5 2 2
1 2 3 4 5


Sample output:
4.500000
1

Submission status: Runtime Error

Solution code:
#57d
from bisect import bisect_left, bisect_right
from scipy.special 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: Runtime Error

Solution code:
def count(v,n,x):
    result = 0
    for i in range(n):
        if v[i] == x:
            result += 1
    return result

def getAverage(v,a):
    result = 0
    for i in range(a):
        result += v[i]
    return result/a

choose = [[1]*51 for i in range(51)]
for i in range(1,51):
    for j in range(1,i):
        choose[i][j] = choose[i-1][j] + choose[i-1][j-1]

n,a,b = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
v.sort()
v = v[::-1]

ans = 0
min = v[a-1]
i=0
while (getAverage(v,a)==getAverage(v,a+i) and a+i<=b):
    count1 = count(v,a+i,min)
    count2 = count(v,len(v),min)
    ans += choose[count2][count1]
    i += 1

print("%.9f" % (getAverage(v,a)))
print(ans)

Submission status: Runtime Error

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:
	print(cnt,v[ind])
	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[795366679311762],M2[795366679311762])
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: Runtime Error

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] 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

print(int(ways))

Submission status: Runtime Error

Solution code:
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
import scipy.special

def comb(n, r):
    return scipy.special.comb(n, r, exact=True)

n, a, b, *v = map(int, sys.stdin.read().split())

def main():
    v.sort()

    ma = v[n-a:n]
    yield sum(ma) / a

    lo = ma[0]
    hi = ma[-1]

    res = 0
    lo_cnt = bi_r(v, lo) - bi_l(v, lo)
    if lo == hi:
        for c in range(a, min(b, lo_cnt) + 1):
            res += comb(lo_cnt, c)
    else:
        allowed_cnt = bi_r(ma, lo)
        res = comb(lo_cnt, allowed_cnt)
    
    yield res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Runtime Error

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

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

Solution code:
from math import factorial
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 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,b+1):
    ans+=cmb(k,i)
  print(ans)
else:
  print(1)

Submission status: Runtime Error

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, B + 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: Runtime Error

Solution code:
N, W = map(int, input().split())
w0, v0 = map(int, input().split())
X = [[] for _ in range(4)]
X[0].append(v0)
for _ in range(N-1):
    w, v = map(int, input().split())
    X[w-w0].append(v)

X = [[0] + sorted(x)[::-1] for x in X]
for i in range(4):
    for j in range(1, len(X[i])):
        X[i][j] += X[i][j-1]
ma = 0
for i in range(N+1):
    for j in range(N+1-i):
        for k in range(N+1-i-j):
            l = min(N-i-j-k, (W - (w0 * i + (w0+1) * j + (w0+2) * k)) // (w0+3))
            if l < 0: continue
            if i < len(X[0]) and j < len(X[1]) and k < len(X[2]) and l < len(X[3]):
                ma = max(ma, X[0][i] + X[1][j] + X[2][k] + X[3][l])
print(ma)

Submission status: Runtime Error

Solution code:
import math
def pcount(n, r):
    return math.factorial(n) // (math.factorial(r)* math.factorial(n - r))

n, a, b = map(int, input().split())
L = [int(i) for i in input().split()]
L.sort(reverse=True)

T = L[:a]
print(sum(T)/a)

s = 0
Tmin = min(T)
countTminT = T.count(Tmin)
countTminL = L.count(Tmin)

if a == 1 and countTminL == 1:
  s = 1
elif countTminT == a:
  for i in range(a,b+1):
    s += pcount(countTminL, i)
else:
  s += pcount(countTminL, countTminT)

print(s)

Submission status: Runtime Error

Solution code:
import math

nab = [int(x) for x in input().split()]
n = nab[0]
a = nab[1]
b = nab[2]
counts = []
nums = [int(x) for x in input().split()]
means = []
nums.sort(reverse = True)
for i in range(a, b+1):
  #means.append(sum(nums[:i])/i)
    
  
  j = i
  while j<n:
    if nums[j-1]==nums[j]:
      j+=1
    else:
      break
  
  for k in range(int(math.factorial(j)/(math.factorial(i)*math.factorial(j-i)))):
    means.append(sum(nums[:i])/i)
  #counts.append(math.comb(j, i))
  print(math.factorial(j)/(math.factorial(i)*math.factorial(j-i)))
  print(math.factorial(4)/(math.factorial(2)*math.factorial(2)))
  print(math.factorial(4))
  print(j, i)
print(max(means))
#print(counts[
print(means.count(max(means)))

'''
def C(n, k):
  return C(n-1, k-1) + C(n-1, k)
  
for n in range(MAX_N):
  for k in range(MAX_K):
    C[n][k] = C[n-1][k-1] + C[n-1][k]

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(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

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    ave = 0
    ans = 0
    if sort_v[0] == sort_v[A-1]:
        cnt = v.count(sort_v[A-1])
        ave = sort_v[0]
        for i in range(A, min(cnt,B)+1):
            ans += cmb(cnt,i)
    else:
        cnt = v.count(sort_v[A-1])
        ind = sort_v.index(sort_v[A-1])
        for i in range(ind, A):
            ans += cmb(cnt, i)
        tmp = 0
        for i in range(A):
            tmp += sort_v[i]
        ave = tmp / A
    print(ave)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n, a, b = map(int,input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
max_avg = sum(v[:a]) / a
min_v = min(v[:a])


ans = 0
for i in range(a, b+1):
    if max_avg != sum(v[:i]) / i: break
    cnt1 = v[:i].count(min_v)
    cnt2 = v.count(min_v)
    ans += comb(cnt2, cnt1)

print(max_avg)
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
x.reverse()

j=a+1
moto=0
h=0
d=x[a-1]
asd=0
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(moto/a)
if x[0]==x[a-1]:
  for i in range(a,b+1):
    asd+=math.factorial(l)//(math.factorial(l-i)*math.factorial(i))
  print(asd)
else:
  print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h)))

Submission status: Runtime Error

Solution code:
import math
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
x.reverse()

j=a+1
moto=0
h=0
d=x[a-1]
asd=0
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(moto/a)
if moto/a==x[a-1]:
  for i in range(a,b+1):
    asd+=math.factorial(l)//(math.factorial(l-i)*math.factorial(i))
  print(asd)
else:
  print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h)))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
ans=0
for i in range(a):
    ans+=v[i]
ans/=a
k=a-1
count=1
while k<=n-2:
    if v[k]==v[k+1]:
        count+=1
        k+=1
        continue
    else:
        break
k=a-1
cnt=1
while k>=1:
    if v[k]==v[k-1]:
        count+=1
        cnt+=1
        k-=1
        continue
    else:
        break
print(ans)

l=n
for i in range(1,n):
    if v[i]==v[0]:
        continue
    else:
        l=i
        break
        
from operator import mul
from functools import reduce

def cmb(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
print(l)
if l<a:
    print(cmb(count,cnt))
if a<=l<=b:
    x=0
    for i in range(a,l+1):
        x+=cmb(l,i)
    print(x)
else:
    x=0
    for i in range(a,b+1):
        x+=cmb(l,i)
    print(x)

Submission status: Runtime Error

Solution code:
from collections import Counter 
def binomialCoeff(n , k): 
    C = [0 for i in range(k+1)] 
    C[0] = 1
  
    for i in range(1,n+1): 
        j = min(i ,k) 
        while (j>0): 
            C[j] = C[j] + C[j-1] 
            j -= 1
    return C[k] 

n,x,b=map(int,input().split())
mp={}
a=list(map(int,input().split()))
mp=Counter(a)
a=list(set(a))
a.sort()
ss=0
pq=0
op=0
tot=0
ox=0
for i in range(len(a)-1,-1,-1):
    if(ss+mp.get(a[i])>x):
        hp=x-ss
        oi=mp.get(a[i])
        tot=oi
        op=hp
        pq+=hp*a[i]
        ss+=hp
        ox=a[i]
        break
    else:
        ss+=mp.get(a[i])
        pq+=a[i]*mp.get(a[i])
print(pq/ss)
if(mp.get(ox)==n):
    on=0
    for i in range(a,b+1):
        on=max(on,binomialCoeff(n,i))
    print(on)
else:
    print(binomialCoeff(tot,op))

Submission status: Runtime Error

Solution code:
from collections import Counter 
def binomialCoeff(n , k): 
    if k==0 or k ==n : 
        return 1 
    return binomialCoeff(n-1 , k-1) + binomialCoeff(n-1 , k)

n,x,b=map(int,input().split())
mp={}
a=list(map(int,input().split()))
mp=Counter(a)
a=list(set(a))
a.sort()
ss=0
pq=0
op=0
tot=0
for i in range(len(a)-1,-1,-1):
    if(ss+mp.get(a[i])>x):
        hp=x-ss
        oi=mp.get(a[i])
        tot=oi
        op=hp
        pq+=hp*a[i]
        ss+=hp
        break
    else:
        ss+=mp.get(a[i])
        pq+=a[i]*mp.get(a[i])
print(pq/a)
if(tot!=0):
    print(binomialCoeff(tot,op))
else:
    print(1)

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
least = nums[A-1]
cnt = 1
for i in range(A-1)[::-1]:
  if nums[i] == least:
    cnt += 1
need = cnt
for i in range(A, B+1):
  if nums[i] == least:
    cnt += 1
  else:
    break
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)]
ans = 0
if cnt == N:
  print(least)
  for i in range(1, N+1):
    ans += cmb(N, i)
else:
  print(sum(nums[:A])/A)
  ans = cmb(cnt, need)
print(ans)

Submission status: Runtime Error

Solution code:
def nck(n, k):
    ret = 1
    for i in range(min(n - k, k)):
        ret *= (n - i)
        ret /= (i + 1)
    return ret


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

    v = sorted(v, reverse=True)
    d = defaultdict(int)
    for i in range(n):
        d[v[i]] += 1
    value = 0
    c = 0
    t = 0
    for i in range(b):
        if i < a:
            value += v[i]

            if i == a - 1:
                t = v[i]
    for i in range(n):
        if v[i] == t:
            break
        c += d[v[i]]
    print(value / a)
    ans = 0
    if d[v[i]] == n:
        for i in range(1, b+1):
            if i >= a:
                ans += nck(d[t], i)
        print(ans)
    else:
        print(nck(d[t], a - c))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    L = [i for i in range(1, U) if N % i == 0]
    C = [U] if M % U == 0 else []
    R = [N // r for r in reversed(L)]
    return L + C + R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Runtime Error

Solution code:
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
if a==n:
  print(sum(v)/n)
  print(1)
elif v[a-1]!=v[a]:
  print(sum(v[0:a])/a)
  print(1)
elif v[0]!=v[a-1]:
  print(sum(v[0:a])/a)
  ct1=0;ct2=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
      if i<a:
        ct2+=1
  print(math.factorial(ct1)//(math.factorial(ct1-ct2)*math.factorial(ct2)))
else:
  print(sum(v[0:a])/a)
  ct1=0;ans=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
  for i in range(a,b+1):
    ans+=math.factorial(ct1)//(math.factorial(ct1-i)*math.factorial(i))
  print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
import sys
from scipy.special import comb
import heapq
import math

input = sys.stdin.readline

sys.setrecursionlimit(10000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N, A, B = [int(a) for a in input().split()]
    V = sorted([int(a) for a in input().split()], reverse=True)

    s = sum(V[:A]) / A
    target = V[A - 1]
    if target == V[0]:
        co = V.count(target)
        t = sum(
            comb(co, c, exact=True)
            for c in range(A, min(B, co) + 1)
        )
        print(s)
        print(t)
        return

    c1 = V[:A].count(target)
    c2 = V.count(target)
    t = comb(c2, c1, exact=True)
    print(s)
    print(t)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = 0
    for i in range(A, B + 1):
        # print(i, num_replace_in_list, num_replace)
        if i - A + num_replace_in_list > num_replace:
            break
        ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))

print(ans)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a] < v[n-1]:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count0 = 0
        for i in range(b):
            if v[n-i-1] == v[n-i]:
                count0 = count0 + 1 
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(n-x+1))//x
        for i in range(a,count0+1):
            c = c*(50-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Runtime Error

Solution code:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        if num == 1:
            print(1)
            exit()
        for i in range(A,B+1):
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)

ans = 0
if v[A-1] == v[0]:
    mean = v[0]
    count = 0
    for i in range(N):
        if v[i] == v[0]:
            count += 1
    for i in range(A,min(B,count)+1):
        ans += comb(count,i,exact=True)
else:
    mean = sum(v[:A])/A
    count = 0
    j = N
    for i in range(N):
        if v[i] == v[A-1]:
            j = min(i,j)
            count += 1
    ans = comb(count,A-j,exact=True)
print(mean)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import operator as op
import numpy
import math

def combination_table(N):
	C = []
	for i in range(N+1):
		C.append([0] * (N+1))
	for i in range(N+1):
		for j in range(i+1):
			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

if __name__ == "__main__":
	N, A, B = stdin.readline().split(" ")
	N = int(N)
	A = int(A)
	B = int(B)
	V = []
	line = stdin.readline().split(" ")
	unique_elements = dict()
	for e in line:
		V.append(int(e)) 
		if not int(e) in unique_elements:
			unique_elements[int(e)] = 1
		else:
			unique_elements[int(e)] += 1
	V.sort(reverse=True)

	C = combination_table(3)

	# find optimal selections between A and B
	optimal = [A]
	highest_avg = -1
	for i in range(A, B+1):
		avg = float(sum(V[:i])) / float(i)
		if (avg > highest_avg):
			highest_avg = avg
			optimal = [i] # reset the list
		elif (avg == highest_avg):
			if not i in optimal:
				optimal.append(i)

	total = 1
	for e in optimal:
		# unique elements and count in for optimal value
		op_elemements = dict()
		for i in range(e):
			if V[i] in op_elemements:
				op_elemements[V[i]] += 1
			else:
				op_elemements[V[i]] = 1

		# find the sum
		for key, value in op_elemements.items():
			# print (unique_elements[key], value, C[unique_elements[key]][value])
			total = total * C[unique_elements[key]][value]

	print ("{:6f}".format(highest_avg))
	print (int(total))

Submission status: Runtime Error

Solution code:
from sys import stdin
import operator as op
from functools import reduce

def nCr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom

if __name__ == "__main__":
	N, A, B = stdin.readline().split(" ")
	N = int(N)
	A = int(A)
	B = int(B)
	V = []
	line = stdin.readline().split(" ")
	unique_elements = dict()
	for e in line:
		V.append(int(e)) 
		if not int(e) in unique_elements:
			unique_elements[int(e)] = 1
		else:
			unique_elements[int(e)] += 1
	V.sort(reverse=True)


	# find optimal selections between A and B
	optimal = [A]
	highest_avg = -1
	for i in range(A, B+1):
		avg = float(sum(V[:i])) / float(i)
		if (avg > highest_avg):
			highest_avg = avg
			optimal = [i] # reset the list
		elif (avg == highest_avg):
			if not i in optimal:
				optimal.append(i)

	total = 1
	for e in optimal:
		# unique elements and count in for optimal value
		op_elemements = dict()
		for i in range(e):
			if V[i] in op_elemements:
				op_elemements[V[i]] += 1
			else:
				op_elemements[V[i]] = 1

		# find the sum
		for key, value in op_elemements.items():
			total = total * nCr(unique_elements[key], value)

	print ("{:6f}".format(highest_avg))
	print (int(total))

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N, A, B = l_inpl()
v = l_inpl()

sort_v = sorted(v, reverse=True)
ans_1 = sum(sort_v[:A])/A
print(ans_1)

max_v = sort_v[A-1]
max_v_count = sort_v.count(max_v)
max_v_count_in_ans = sort_v[:A].count(max_v)

if max_v != sort_v[0]: # 1つでも増やすと平均が減少する場合
    ans = comb(max_v_count, max_v_count_in_ans)
else:
    ans = 0
    for i in range(A, min(B, max_v_count) + 1):
        ans += comb(max_v_count, i)

print(int(ans))

Submission status: Runtime Error

Solution code:
def pascal(n,r):
    global p
    while len(p)<50:
        pi=[1]
        for i in range(len(p)):
            pi.append(p[-1][i]+p[-1][i+1])
        pi.append(1)
        p.append(pi)
    return p[n-1][r]

n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())))[::-1]
va=v[:a]
val=va[-1]
print(sum(va)/a)
p=[[1,1]]
if len(set(va))>1:
    print(pascal(v.count(val),va.count(val)))
elif v.count(val)==1:
    print(1)
else:
    m=v.count(val)
    x=0
    for i in range(a,b+1):
        x+=pascal(m,i)
    print(x)

Submission status: Runtime Error

Solution code:
def pascal(n,r):
    global p
    while len(p)<n:
        pi=[1]
        for i in range(len(p)):
            pi.append(p[-1][i]+p[-1][i+1])
        pi.append(1)
        p.append(pi)
    return p[n-1][r]

n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())))[::-1]
va=v[:a]
val=va[-1]
print(sum(va)/a)
p=[[1,1]]
if len(set(va))>1:
    print(pascal(v.count(val),va.count(val)))
elif v.count(val)==1:
    print(1)
else:
    m=v.count(val)
    x=0
    for i in range(a,b+1):
        x+=pascal(m,i)
    print(x)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
import bisect

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))

n,a,b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
if v[0] == v[a-1]:
  print(v[0])
  c = v.count(v[a-1])
  ans = 0
  for i in range(a,b+1):
    ans += cmb(c,i)
  print(ans)
else:
  print(sum(v[:a]) / a)
  c = v.count(v[a-1])
  d = 0
  for key,value in enumerate(v):
    if value == v[a-1]:
      d = key
      break
  print(cmb(c,a-d))

Submission status: Runtime Error

Solution code:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
def comb(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)
max_mean = sum(v[0:a])/a
print(max_mean)
#選び方の総数を求める
c = Counter(v)
i = 0
num = 0
ans = 0
while num<=a:
    if num+c[v[i]]>=a:
        num += c[v[i]]
    else:
        i +=1
        num += c[v[i]]
if i > 0:
    ans += comb(c[v[i]],a)
    print(ans)
else:
    for i in range(a,b+1):
        if c[v[0]] >=i:
            ans += comb(c[v[0]],i)
    print(ans)

Submission status: Runtime Error

Solution code:
def value_and_count(x):
    d = {}
    for xi in x:
        if xi in d.keys():
            d[xi] += 1
        else:
            d[xi] = 1
    return d

def comb(n, k):
    k = min(n - k, k)
    denominator = 1 # 分母
    numerator = 1 # 分子
    for i in range(k):
        denominator *= i + 1
        numerator *= n - i
    return numerator // denominator

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
d_v = value_and_count(v)
v.sort(reverse=True)
sum_v = sum(v[:a])
print(sum_v / a)

ans = 0
d_vk = None
for k in range(a, b + 1):
    vk = v[:k]
    sum_vk = sum(vk)
    if sum_vk < sum_v:
        break

    if d_vk is None:
        d_vk = value_and_count(vk)
    else:
        d_vk[vk[-1]] += 1

    ans_k = 1
    for vi, ci in d_vk.items():
        ans_k *= comb(d_v[vi], ci)
    ans += ans_k

print(ans)

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.7f}".format(sum(v[0:a])/a))
    if v[0] == c:
        ans = 0
        for i in range(a, b+1):
            ans += comb(total, i)
        print(ans)
    else:
        print(int(comb(total, cnt1)))

solve()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

long long Combination(int n, int r) {
  vector<vector<long long>> C(n + 1, vector<long long>(n + 1, 1));
  for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  return C[n][r];
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  sort(v.begin(), v.end(), greater<int>());
  double ans1 = 0;
  for (int i = 0; i < A; i++) ans1 += v[i];
  ans1 /= A;
  long long ans2 = 0;
  if (v[0] == v[A - 1]) {
    int n = 0;
    for (int i = 0; i < N; i++) if (v[i] == v[0]) n++;
    for (int r = A; r <= B; r++) ans2 += Combination(n, r);
  } else {
    int n = 0, r = 0;
    for (int i = 0; i < N; i++) if (v[i] == v[A - 1]) n++;
    for (int i = 0; i < A; i++) if (v[i] == v[A - 1]) r++;
    ans2 = Combination(n, r);
  }
  cout << fixed << ans1 << endl << ans2 << endl;
}

Submission status: Runtime Error

Solution code:
def fuct(n:int)->int:
    if n==1:
        return 1
    else:
        return n * fuct(n-1)

def main():
    n,a,b = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v, reverse=True)
    print(sum(v[:a])/a)
    res = 0

    if v[0]==v[a-1]:
        vn = v.count(v[0])
        for r in range(a,b+1):
            res += fuct(vn)//(fuct(vn-r) * fuct(r))
    else:
        vn = v.count(v[a-1])
        r = v[:a].count(v[a-1])
        res += fuct(vn)//(fuct(vn-r) * fuct(r))

    print(res)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
N=int(input())
for i in reversed(range(1,math.ceil(math.sqrt(N))+1)):
    if N%i==0:
        B=N//i
        print(math.floor(math.log10(B))+1)
        break