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:
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 ** 5):
    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)
for k in range(a, b+1):
    tot = lb * k

    s = []
    for i in range(k):
        s.append(v[i])
    if sum(s) != tot:
        continue

    tmp = 1
    c = Counter(s)
    for key in c.keys():
        tmp *= combs(c0[key], c[key])
    ans += tmp
print(ans)

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(1000):
    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)
for k in range(a, b+1):
    tot = lb * k
    if int(tot) != tot:
        continue

    tmp = 1
    s = []
    for i in range(k):
        s.append(v[i])
    if sum(s) != tot:
        continue

    c = Counter(s)
    for key in c.keys():
        tmp *= combs(c0[key], c[key])
    ans += tmp
print(ans)

Submission status: Wrong Answer

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-countTminT,b+1-countTminT):
    s += pcount(countTminL, i)
else:
  s += pcount(countTminL, countTminT)

print(s)

Submission status: Wrong Answer

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 = 0
    #s += pcount(countTminL, i)
else:
  s += pcount(countTminL, countTminT)

print(s)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[n-a:]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	
ave = sum(new_v)/a
print("{0:.16f}".format(ave))

if ave in v[:n-a]:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i+a)

print(x)

Submission status: Wrong Answer

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(max(means))
#print(counts[
print(means.count(max(means)))

Submission status: Wrong Answer

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<len(nums)-1:
    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(max(means))
#print(counts[
print(means.count(max(means)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[n-a:]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	
ave = sum(new_v)/a
print(ave)

if ave in v[:n-a]:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i+a)

print(x)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[n-a+1:]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	
ave = sum(new_v)/a
print(ave)

if ave in v[:n-a]:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i+a)

print(x)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[:-a-1:-1]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	
ave = sum(new_v)/a
print(ave)

if ave in v[:n-a]:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i+a)

print(x)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[:-a-1:-1]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	
ave = sum(new_v)/a
print(ave)

if ave in v[:n-a]:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i)

print(x)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[:-a-1:-1]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	mydict[key] -= mynewdict[key]

	
ave = sum(new_v)/a
print(ave)

if int(ave) == ave:
	for i in range(1,b-a+1):
		x += ncr(mydict[ave],i)

print(x)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)
	
	if n == 0 or n < r:
		return 0
	return numer // denom

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[:-a-1:-1]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	mydict[key] -= mynewdict[key]

	
ave = sum(new_v)/a
print(ave)

for i in range(1,b-a+1):
	x += ncr(mydict[ave],i)

print(x)

Submission status: Wrong Answer

Solution code:
nab = [int(x) for x in input().split()]
n = nab[0]
a = nab[1]
b = nab[2]
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)
print(max(means))
print(means.count(max(means)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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

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

mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)

for num in v:
	mydict[num]+=1

new_v = v[:-a-1:-1]

for num in new_v:
	mynewdict[num]+=1

x = 1
for key in mynewdict:
	x *= ncr(mydict[key], mynewdict[key])
	mydict[key] -= mynewdict[key]

	
ave = sum(new_v)/a
print(ave)

for i in range(1,b-a+1):
	x += ncr(mydict[ave],i)

print(x)

Submission status: Wrong Answer

Solution code:
def getMean(l):
  return sum(l)/len(l)
def getPerms(l, lOrig):
  sL = set(l)
  product = 1
  for s in sL:
    product *= lOrig.count(s)
  return product

[n,a,b] = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]

"""
top = "5 2 4"
bot = "8 5 9 9 8"

[n,a,b] = [int(x) for x in top.split()]
nums = [int(x) for x in bot.split()]
"""

nums.sort(reverse = True)

ac = 0
bc = 0

l = []
bigMean = 0
for num in nums:
  ac += 1
  bc += 1
  l.append(num)
  if bc == b:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l[:]
    break
  elif ac >= a:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l[:]

print(bigMean)
print(getPerms(bigL, nums))

"""
4 2 3
3 4 5 5
"""

Submission status: Wrong Answer

Solution code:
def getMean(l):
  return sum(l)/len(l)
def getPerms(l, lOrig):
  sL = set(l)
  product = 1
  for s in sL:
    product *= lOrig.count(s)
  return product

#[n,a,b] = [int(x) for x in input().split()]
#nums = [int(x) for x in input().split()]

top = "5 2 4"
bot = "8 5 9 9 8"

[n,a,b] = [int(x) for x in top.split()]
nums = [int(x) for x in bot.split()]


nums.sort(reverse = True)

ac = 0
bc = 0

l = []
bigMean = 0
for num in nums:
  ac += 1
  bc += 1
  l.append(num)
  if bc == b:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l[:]
    break
  elif ac >= a:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l[:]

print(bigMean)
print(getPerms(bigL, nums))

"""
4 2 3
3 4 5 5
"""

Submission status: Wrong Answer

Solution code:
def getMean(l):
  return sum(l)/len(l)
def getPerms(l, lOrig):
  sL = set(l)
  product = 1
  for s in sL:
    product *= lOrig.count(s)
  return product

[n,a,b] = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort(reverse = True)

ac = 0
bc = 0

l = []
bigMean = 0
for num in nums:
  ac += 1
  bc += 1
  l.append(num)
  if bc == b:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l
    break
  elif ac >= a:
    if getMean(l) > bigMean:
      bigMean = getMean(l)
      bigL = l

print(bigMean)
print(getPerms(bigL, nums))

Submission status: Wrong Answer

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

new_v = v[:-a-1:-1]
ave = sum(new_v)/a
print(ave)

set_v = list(set(new_v))

counts = [0]*len(set_v)
for i in range(len(set_v)):
	counts[i] = v.count(set_v[i])

x = 1
for num in counts:
	x*=num

print(x)

Submission status: Wrong Answer

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

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

V.sort(reverse=True)

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

ans2 = 1
cnt = V.count(V[0])
if cnt > A:
    ans2 = 0
    for i in range(A,min(B,cnt)+1):
        tmp = 1
        for j in range(i):
            tmp *= cnt-j
            tmp //= j+1
        ans2 += tmp
else:
    cnt1 = V.count(V[A-1])
    cnt2 = V[:A].count(V[A-1])
    if cnt2 > 1:
        for i in range(cnt2):
            ans2 *= cnt1-i
            ans2 //= i+1

print(ans1)
print(ans2)

Submission status: Wrong Answer

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]
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(moto/a)
print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h)))

Submission status: Wrong Answer

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]
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h)))   
print(moto/a)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
ave=0
for i in range(a):
  ave+=v[i]
  
print(ave/a)

l=0
for j in range(a,b):
  if v[a-1]==v[j]:
    l+=1
    
p=v.count(v[a-1])

from math import factorial
a=factorial(p) / factorial(p-l) / factorial(l)
print(a)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
ave=0
for i in range(a):
  ave+=v[i]
  
print(ave/a)

l=0
for j in range(a,b):
  if v[a-1]==v[j]:
    l+=1
    
print(l)

Submission status: Wrong Answer

Solution code:
from math import factorial as fact
n = list(map(int, input().split()))
l = list(map(int, input().split()))

l = sorted(l)

summ = 0

for i in range(n[1]):
  summ+=l[len(l)-1-i]

avg = float(summ)/n[1]
last =  l[len(l)-n[1]]
lasts = l.count(last)
more = sum(1 for i in l if i>last)
print(avg)
allow = n[1] - more
denom = fact(allow)*fact(lasts-allow)
answer = fact(lasts)/denom
print(int(answer))

Submission status: Wrong Answer

Solution code:
from math import factorial as fact
n = list(map(int, input().split()))
l = list(map(int, input().split()))

l = sorted(l)

summ = 0

for i in range(n[1]):
  summ+=l[len(l)-1-i]

avg = float(summ)/n[1]
last =  l[len(l)-n[1]]
lasts = l.count(last)
more = sum(1 for i in l if i>last)
print(avg)
allow = n[1] - more
answer = fact(lasts)/fact(allow)/fact(lasts-allow)
print(int(answer))

Submission status: Wrong Answer

Solution code:
from math import factorial as fact
n = list(map(int, input().split()))
l = list(map(int, input().split()))

l = sorted(l)

summ = 0

for i in range(n[1]):
  summ+=l[len(l)-1-i]

avg = float(summ)/n[1]
last =  l[len(l)-n[1]]
lasts = l.count(last)
more = sum(1 for i in l if i>last)
print(avg)
allow = n[1] - more
answer = fact(lasts)/fact(allow)/fact(lasts-allow)
print(answer)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
d=l[a-1]
dk=0
for i in l:
    if i==d:
        dk+=1
if dk==1:
    print(sum(l[:a])/(1.0*a))
    print(1)
    exit()
if max(l[:a])==min(l[:a]):
    print(d*1.0)
    print(2**(min(dk,b))-2**(min(dk,a)-1))
else:
    print(sum(l[:a])/(1.0*a))
    dka=0
    for i in range(a):
        if l[i]==d:
            dka+=1
    k=1
    for i in range(dk-dka+1,dk+1):
        k*=i
    for i in range(1,dka+1):
        k=k//i
    print(k)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
d=l[a-1]
dk=0
for i in l:
    if i==d:
        dk+=1
if d==1:
    print(sum(l[:a])/(1.0*a))
    print(1)
    exit()
if max(l[:a])==min(l[:a]):
    print(d*1.0)
    print(2**(min(dk,b))-2**(min(dk,a)-1))
else:
    print(sum(l[:a])/(1.0*a))
    dka=0
    for i in range(a):
        if l[i]==d:
            dka+=1
    k=1
    for i in range(dk-dka+1,dk+1):
        k*=i
    for i in range(1,dka+1):
        k=k//i
    print(k)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
d=l[a-1]
dk=0
for i in l:
    if i==d:
        dk+=1
if d==1:
    print(sum(l[:a])/(1.0*a))
    print(1)
    exit()
if max(l[:a])==min(l[:a]):
    print(dk*1.0)
    print(2**(min(dk,b))-2**(min(dk,a)-1))
else:
    print(sum(l[:a])/(1.0*a))
    dka=0
    for i in range(a):
        if l[i]==d:
            dka+=1
    k=1
    for i in range(dk-dka+1,dk+1):
        k*=i
    for i in range(1,dka+1):
        k=k//i
    print(k)

Submission status: Wrong Answer

Solution code:
from statistics import mean
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values[:b].count(min_value)

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

print(cmb(full, accepted))

Submission status: Wrong Answer

Solution code:
from statistics import mean
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

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

print(cmb(full, accepted))

Submission status: Wrong Answer

Solution code:
from statistics import mean
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

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


print(cmb(full, accepted))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
d = dd(int)
sd = dd(int)
res = 1
nCr = {}
def cmb(n, r):
  global nCr
  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)]

for i in range(N):
  d[v[i]] += 1
r = sum(v[: A])
s = v[: A]
sdsum = 0
for t in s:
  sd[t] += 1
  sdsum += 1
kss = sorted(sd.keys())
#print(d, sd)
f = 0
for k in range(A, B + 1):
  if k % sdsum == 0:
    j = k // sdsum
    t = 1
    for i in range(len(kss)):
      a = kss[i]
      if d[a] < sd[a] * j:
        f = 1
        break
      t *= cmb(d[a], sd[a] * j)
      #print(d[a], sd[a] * j)
    if f:
      break
    res += t
print(r / A)
print(res - 1)

Submission status: Wrong Answer

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(x,b+1):
        on=max(on,binomialCoeff(n,i))
    print(on)
else:
    print(binomialCoeff(tot,op))

Submission status: Wrong Answer

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.sort(reverse=True)
pq=sum(a[:x])
op=a[x:].count(a[x-1])
tot=mp.get(a[x-1])
print(pq/x)
print(binomialCoeff(tot,op))

Submission status: Wrong Answer

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.sort(reverse=True)
pq=sum(a[:x])
op=a[x:].count(a[x-1])
tot=mp.get(a[x-1])
print(pq/x)
print(binomialCoeff(tot,op))

Submission status: Wrong Answer

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/x)
if(tot!=0):
    print(binomialCoeff(tot,op))
else:
    print(1)

Submission status: Wrong Answer

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/ss)
if(tot!=0):
    print(binomialCoeff(tot,op))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort(reverse=1)
sm=sum(l[:a])
from math import factorial as f 
def ncr(n,k): 
    return f(n)//(f(k)*f(n-k)) 
print(sm/a)
s=set(l)
s=list(s)
s.sort(reverse=1)
cnt=0 
ans=0 
from collections import Counter
c=Counter(l)
for i in s:
    if cnt+c[i]<a:
        cnt+=c[i]
    else:
        ans=ncr(c[i],(a-cnt))
        break 
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort(reverse=1)
sm=sum(l[:a])
from math import factorial as f 
def ncr(n,k): 
    return f(n)//(f(k)*f(n-k)) 
print(sm/a)
s=set(l)
s=list(s)
s.sort()
cnt=0 
ans=0 
from collections import Counter
c=Counter(l)
for i in s:
    if cnt+c[i]<a:
        cnt+=c[i]
    else:
        ans=ncr(c[i],(a-cnt))
        break 
print(ans)

Submission status: Wrong Answer

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


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
v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[:a])/a)
if v[a-1]!=v[a]:
    print(1)
else:
    ans=0
    k=v[a-1:b].count(v[a-1])
    for i in range(1,k+1):
        ans+=cmb(k,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from math import factorial
def ncr(n,r):
  if n-r <= 0 or n <= 0 or r <= 0:
    return 1
  else:
    return factorial(n) / factorial(r) / factorial(n - r)

def solve():
  n,a,b = (int(i) for i in input().split())
  v = list(int(i) for i in input().split())
  v = sorted(v,reverse = True)
  av = 0
  for i in range(a):
    av += v[i]
    lastv = v[i]
  av /= a
  print(av)
  count = v.count(lastv)
  ans = 0
  if count == n:
    for i in range(a,b+1):
      ans += ncr(n,i)
  else:
    v2 = v[0:a]
    tmp = v2.count(lastv)
    ans += ncr(count,tmp)
  print(int(ans))
            
solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from math import factorial
def ncr(n,r):
  if n-r <= 0 or n <= 0 or r <= 0:
    return 0
  else:
    return factorial(n) / factorial(r) / factorial(n - r)

def solve():
  n,a,b = (int(i) for i in input().split())
  v = list(int(i) for i in input().split())
  v = sorted(v,reverse = True)
  av = 0
  for i in range(a):
    av += v[i]
    lastv = v[i]
  av /= a
  print(av)
  count = v.count(lastv)
  ans = 0
  if count == n:
    for i in range(a,b+1):
      ans += ncr(n,i)
  else:
    v2 = v[0:a]
    tmp = v2.count(lastv)
    ans += ncr(count,tmp)
  print(int(ans))
            
solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from math import factorial
def ncr(n,r):
  return factorial(n) / factorial(r) / factorial(n - r)

def solve():
  n,a,b = (int(i) for i in input().split())
  v = list(int(i) for i in input().split())
  v = sorted(v,reverse = True)
  av = 0
  for i in range(a):
    av += v[i]
    lastv = v[i]
  av /= a
  print(av)
  count = v.count(lastv)
  ans = 0
  if count == n:
    for i in range(a,b+1):
      ans += ncr(n,i)
  else:
    v2 = v[0:a]
    tmp = v2.count(lastv)
    ans += ncr(count,tmp)
  print(int(ans))
            
solve()

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
d = [[0] * (n + 1) for _ in range(n + 1)]
d[0][0] = 1
for i in range(n):
    for j in range(i + 1):
        if dp[i + 1][j] < dp[i][j]:
            d[i + 1][j] = d[i][j]
            dp[i + 1][j] = dp[i][j]
        elif dp[i + 1][j] == dp[i][j]:
            d[i + 1][j] += d[i][j]
        if dp[i + 1][j + 1] < dp[i][j] + v[i]:
            d[i + 1][j + 1] = d[i][j]
            dp[i + 1][j + 1] = dp[i][j] + v[i]
        elif dp[i + 1][j + 1] == dp[i][j] + v[i]:
            d[i + 1][j + 1] += d[i][j]
ans = 0
idx = 0
cnt = 0
for i in range(a, b + 1):
    if dp[n][i] > ans * i:
        ans = dp[n][i]
        idx = i
        cnt = d[n][i]
    elif dp[n][i] == ans * i:
        cnt += d[n][i]
print(ans / idx)
print(cnt)

Submission status: Wrong Answer

Solution code:
def combinations(N):
    comb = [[0] * (N + 1) for _ in range(N + 1)]
    comb[0][0] = 1
    for i in range(1, N + 1):
        for j in range(i + 1):
            comb[i][j] += comb[i - 1][j]
            if j > 0:
                comb[i][j] += comb[i - 1][j - 1]
    return comb


nCk = combinations(60)

N, A, B, *V = map(int, open(0).read().split())

V.sort(reverse=True)

num = V.count(V[A - 1])

ans = 0
if V[0] == V[A - 1]:
    ans = sum(nCk[num][A:B])
else:
    a = V[:A].count(V[A - 1])
    ans = nCk[num][a]

ave = sum(V[:A]) / A

print("{:.9f}".format(ave))
print(ans)