Problem:


Score : 400 points

Problem Statement

You are given N items.

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

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

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

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

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

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

N A B
v_1
v_2
...
v_N

Output

Print two lines.

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

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

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

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

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

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

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

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1



Sample input:
5 2 2
1 2 3 4 5


Sample output:
4.500000
1

Submission status: Wrong Answer

Solution code:
from math import comb
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
print(sum(v[:a]) / a)
if v[0] != v[a - 1]:
    cur = v[-1]
    cnt = 0
    for i in range(n):
        if cur == v[i]:
            cnt += 1
    cnt2 = 0
    for i in range(a):
        if cur == v[i]:
            cnt2 += 1
    print(comb(cnt, cnt2))
else:
    cur = v[-1]
    cnt = 0
    for i in range(n):
        if cur == v[i]:
            cnt += 1
    ans = 0
    for i in range(a, b + 1):
        ans += comb(cnt, i)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def cmb(n,k):
    over = 1
    under = 1
    for i in range(n-k+1,n+1):
        over *= i
    for i in range(1,k+1):
        under *= i
    return over//under

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
C = Counter(v)
li = sorted(list(C.keys()),reverse=True)
ans = 0
SUM = 0
ave = 0
remain = A
n = C[li[0]]
if n >= A:
    ave = li[0]
    for k in range(A,max(B,n)+1):
        ans += cmb(n,k)
else:
    for i in li:
        if C[i] < remain:
            SUM += i*C[i]
            remain -= C[i]
        else:
            SUM += i*remain
            ans = cmb(C[i],remain)
            ave = SUM/A
            break
print(ave)
print(ans)

Submission status: Wrong Answer

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


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

print(sum(lst[-a:])/a)

pin=lst[-a]
ans=0

l=lst[:-a].count(pin)
r=lst[-a:].count(pin)

for i in range(r,min(l+r+1,b-(a-r))):
    ans+=cmb(l+r,i)


print(ans)

Submission status: Wrong Answer

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


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

print(sum(lst[-a:])/a)

pin=lst[-a]
ans=0

l=lst[:-a].count(pin)
r=lst[-a:].count(pin)

for i in range(r,l+r+1):
    ans+=cmb(l+r,i)


print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#階乗#
lim = 50
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[n-r]//fact[r]


N, A, B = MAP()
v = sorted(LIST(), reverse=True)

V_cnt = Counter(v)
V_max = Counter(v[:A])
key = v[A-1]
print(sum(v[:A])/A)

v = v[::-1]

idx_1 = bisect_left(v, key)
idx_2 = bisect(v, key)
n = idx_2 - idx_1
k = bisect(v, key)
m = N - k


if m == 0:
	ans = 0
	for i in range(A, min(B-m, n)+1):
		print(n, i)
		ans += C(n, i)
	print(ans)
else:
	print(C(n, A-m))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#階乗#
lim = 50
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[n-r]//fact[r]


N, A, B = MAP()
v = sorted(LIST(), reverse=True)

V_cnt = Counter(v)
V_max = Counter(v[:A])
key = v[A-1]
print(sum(v[:A])/A)

v = v[::-1]

idx_1 = bisect_left(v, key)
idx_2 = bisect(v, key)
n = idx_2 - idx_1
k = bisect(v, key)
m = N - k
#print("n={}".format(n))
#print("m={}".format(m))

if m == 0:
	ans = 0
	for i in range(1, min(B-m, n)+1):
		ans += C(n, i)
	print(ans)
else:
	print(C(n, A-m))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#階乗#
lim = 50
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[n-r]//fact[r]


N, A, B = MAP()
v = sorted(LIST(), reverse=True)

V_cnt = Counter(v)
V_max = Counter(v[:A])
key = v[A-1]
print(sum(v[:A])/A)

v = v[::-1]

idx_1 = bisect_left(v, key)
idx_2 = bisect(v, key)
n = idx_2 - idx_1
k = bisect(v, key)
m = N - k

ans = 0
for i in range(1, min(B-m, n)+1):
	ans += C(n, i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#階乗#
lim = 50
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[n-r]//fact[r]


N, A, B = MAP()
v = sorted(LIST(), reverse=True)

V_cnt = Counter(v)
V_max = Counter(v[:A])
key = v[A-1]

v = v[::-1]

idx_1 = bisect_left(v, key)
idx_2 = bisect(v, key)
n = idx_2 - idx_1
k = bisect(v, key)
m = N - k

ans = 0
for i in range(1, min(B-m, n)+1):
	ans += C(n, i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
inp = lambda: sys.stdin.readline()
mi = lambda: map(int, inp().split())
li = lambda: list(map(int, inp().split()))
mf = lambda: map(float,inp().split())
lf = lambda: list(map(float,inp().split()))

def nCk(n,k):
    u,s = 1,1
    for i in range(n - k + 1,n + 1):u *= i
    for i in range(1,k + 1):s *= i
    return u // s
N,A,B = mi()
vec = lf()
vec.sort()
vec = vec[::-1]
avr = 0.0
for i in range(A):
    avr += vec[i]
avr /= A
print("{:.08f}".format(avr))
kosu = vec.count(vec[A - 1])
#print(kosu)
if kosu == 1:
    print(1)
    sys.exit()
if vec[0] == vec[A - 1]:
    ans = 0
    for i in range(A,B + 1):
        if vec[i - 1] != vec[0]:
            break
        ans += nCk(kosu,i)
    print(ans)
else:
    K = vec[:A].count(vec[A - 1])

Submission status: Wrong Answer

Solution code:
import sys
inp = lambda: sys.stdin.readline()
mi = lambda: map(int, inp().split())
li = lambda: list(map(int, inp().split()))
mf = lambda: map(float,inp().split())
lf = lambda: list(map(float,inp().split()))

def nCk(n,k):
    u,s = 1,1
    for i in range(n - k + 1,n + 1):u *= i
    for i in range(1,k + 1):s *= i
    return u // s
N,A,B = mi()
vec = lf()
vec.sort()
vec = vec[::-1]
avr = 0.0
for i in range(A):
    avr += vec[i]
avr /= A
print("{:.08f}".format(avr))
kosu = vec.count(vec[A - 1])
if kosu == 1:
    print(1)
    sys.exit()
if vec[0] == vec[A - 1]:
    ans = 0
    for i in range(A - 1,B):
        if vec[i] != vec[0]:
            break
        ans += nCk(kosu,i)
    print(ans)
else:
    K = vec[:A].count(vec[A - 1])
    print(nCk(kosu,K))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from itertools import product
from random import randint

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def debug(n, a, b, V, ave):
    cnt = 0
    for pattern in product([0, 1], repeat=n):
        if a <= sum(pattern) <= b:
            tot = 0
            for idx, p in enumerate(pattern):
                if p == 1:
                    tot += V[idx]
            res = tot / sum(pattern)
            if abs(res - ave) <= 10 ** -6:
                cnt += 1
    return cnt


def resolve():
    n, a, b = map(int, input().split())
    V = list(map(int, input().split()))

    V.sort(reverse=True)
    ave = 0
    for i in range(a, b + 1):
        tot = sum(V[:i])
        if ave <= tot / i:
            ave = tot / i
            used = V[:i]

    if len(set(used)) == 1:
        ave = used[0]
        res = 1
        cmb = [0] * len(used)
        for i in range(a, len(used) + 1):
            x = y = 1
            for j in range(1, i + 1):
                x *= (len(used) + 1 - j)
                y *= j
            cmb[i - 1] = x // y
        res *= sum(cmb)
    else:
        use_cnt = Counter(used)
        used = set(used)
        D = Counter(V)
        res = 1
        for num in used:
            cnt = use_cnt[num]
            x = y = 1
            for j in range(1, cnt + 1):
                x *= (D[num] + 1 - j)
                y *= j
            res *= x // y
    print(ave)
    print(res)
    # print(debug(n, a, b, V, ave))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from itertools import product
from random import randint

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def debug(n, a, b, V, ave):
    cnt = 0
    for pattern in product([0, 1], repeat=n):
        if a <= sum(pattern) <= b:
            tot = 0
            for idx, p in enumerate(pattern):
                if p == 1:
                    tot += V[idx]
            res = tot / sum(pattern)
            if abs(res - ave) <= 10 ** -6:
                cnt += 1
    return cnt


def resolve():
    n, a, b = map(int, input().split())
    V = list(map(int, input().split()))
    # V = [randint(0, 10 ** 15) for _ in range(n)]

    if len(set(V)) == 1:
        ave = V[0]
        res = 1
        cmb = [0] * b
        for i in range(a, b + 1):
            x = y = 1
            for j in range(1, i + 1):
                x *= (n + 1 - j)
                y *= j
            cmb[i - 1] = x // y
        res *= sum(cmb)
    else:
        V.sort(reverse=True)
        used = []
        ave = 0
        for i in range(a, b + 1):
            tot = sum(V[:i])
            if ave <= tot / i:
                ave = tot / i
                used = V[:i]
        use_cnt = Counter(used)
        used = set(used)
        D = Counter(V)
        res = 1
        for num in used:
            cnt = use_cnt[num]
            x = y = 1
            for j in range(1, cnt + 1):
                x *= (D[num] + 1 - j)
                y *= j
            res *= x // y
    print(ave)
    print(res)
    # print(debug(n, a, b, V, ave))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    V = list(map(int, input().split()))

    if len(set(V)) == 1:
        ave = V[0]
        res = 1
        cmb = [0] * b
        for i in range(1, b + 1):
            x = y = 1
            for j in range(1, i + 1):
                x *= (n + 1 - j)
                y *= j
            cmb[i - 1] = x // y
        res *= sum(cmb)
    else:
        V.sort(reverse=True)
        used = []
        ave = 0
        for i in range(a, b + 1):
            tot = sum(V[:i])
            if ave <= tot / i:
                ave = tot / i
                used = V[:i]
        use_cnt = Counter(used)
        used = set(used)
        D = Counter(V)
        res = 1
        for num in used:
            cnt = use_cnt[num]
            x = y = 1
            for j in range(1, cnt + 1):
                x *= (D[num] + 1 - j)
                y *= j
            res *= x // y
    print(ave)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter, defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    V = list(map(int, input().split()))
    V.sort(reverse=True)

    used = set()
    use_cnt = defaultdict(int)
    for i in range(a - 1):
        used.add(V[i])
        use_cnt[V[i]] += 1

    ave = 0
    for i in range(a, b + 1):
        tot = sum(V[:i])
        if ave <= tot / i:
            ave = tot / i
            used.add(V[i - 1])
            use_cnt[V[i - 1]] += 1
        else:
            break
    res = 1
    D = Counter(V)
    for num in used:
        cnt = use_cnt[num]
        cmb = [0] * cnt
        for i in range(1, cnt + 1):
            x = y = 1
            for j in range(1, i + 1):
                x *= (D[num] + 1 - j)
                y *= j
            cmb[i - 1] = x // y
        res *= sum(cmb)
    print(ave)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N,A,B=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort(reverse=True)
all_n=len(l)
from scipy.special import comb
from collections import Counter
l2=l[0:A]
l=Counter(l)
max_mean=sum(l2)/A
l2=Counter(l2).items()
print(max_mean)
ans=1
if len(set(l))==1:
   ans=0
   for i in range(A,B+1):
      ans+=comb(all_n,i,exact=True)
   print(ans)
   exit()
for i,j in l2:
   all_n=l[i]
   ans*=comb(l[i],j,exact=True)
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
from math import comb
from statistics import mean
print(sum(D[:A])/A)
ans=0
if D[0]!=D[-1]:
  n=D.count(D[A-1])
  k=D[:A].count(D[A-1])
  print(comb(n,k))
else:
  ans=0
  n=D.count(D[A-1])
  way = sum(comb(n, k) for k in range(A, min(n,B)+1))
  print(way)
  #for i in range(A,min(n,B)+1):
    #ans+=comb(n,i)
  #print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
from math import comb
print(sum(D[:A])/A)
ans=0
if D[0]!=D[-1]:
  n=D.count(D[A-1])
  k=D[:A].count(D[A-1])
  print(comb(n,k))
else:
  ans=0
  n=D.count(D[A-1])
  for i in range(A,min(n,B)+1):
    ans+=comb(n,i)
  print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
from math import comb
print(sum(D[:A])/A)
ans=0
if D[0]==D[-1]:
  n=D.count(D[A-1])
  k=D[:A].count(D[A-1])
  print(comb(n,k))
else:
  ans=0
  n=D.count(D[A-1])
  for i in range(A,min(n,B)+1):
    ans+=comb(n,i)
  print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
  print(ans)
else:
  E=sorted(D)
  a=D[A-1]
  l=bisect.bisect_left(E,a)
  r=bisect.bisect_right(E,a)
  #答えは、(r-l)個の中から、A-r+1個選ぶので
  x,y=r-l,r+A-N
  #print(math.factorial(x)//(math.factorial(y)*math.factorial(x-y)))

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
  print(ans)
else:
  E=sorted(D)
  a=D[A-1]
  l=bisect.bisect_left(E,a)
  r=bisect.bisect_right(E,a)
  #答えは、(r-l)個の中から、A-r+1個選ぶので
  x,y=r-l,r+A-N
  print(math.factorial(x)//(math.factorial(y)*math.factorial(x-y)))

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
else:
  a=D.count(D[A-1])
  if a>1:
    b=D[:A].count(D[a-1])
    print(math.factorial(a)//(math.factorial(b)*math.factorial(a-b)))
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
else:
  E=sorted(D)
  a=D[A-1]
  l=bisect.bisect_left(E,a)
  r=bisect.bisect_right(E,a)
  #答えは、(r-l)個の中から、A-r+1個選ぶので
  x,y=r-l,r+A-N
  #print(math.factorial(x)//(math.factorial(y)*math.factorial(x-y)))

Submission status: Wrong Answer

Solution code:
N,A,B=map(int, input().split())
D=list(map(int, input().split()))
D=sorted(D)[::-1]
import math
import bisect
print(sum(D[:A])/A)
ans=0
if D==[D[0]]*N:
  for i in range(A,B+1):
    ans+=math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
else:
  E=sorted(D)
  a=D[A-1]
  l=bisect.bisect_left(E,a)
  r=bisect.bisect_right(E,a)
  #答えは、(r-l)個の中から、A-r+1個選ぶので
  x,y=r-l,r+A-N
  print(math.factorial(x)//(math.factorial(y)*math.factorial(x-y)))

Submission status: Wrong Answer

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

n, a, b = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)
print(sum(l[:a])/a)
if l.count(l[a-1]) > 1:
    ans = 0
    x = l[a-1]
    y = l[:a].count(x)
    for i in range(y, min(l.count(x), b-y)):
        ans += C(l.count(x), i)
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
from math import *
from decimal import Decimal
from collections import defaultdict
N,A,B=map(int,input().split())
v=sorted(map(int,input().split()),reverse=True)

max_mean=0
r=0

for i in range(A-1):
    r+=v[i]
for i in range(A-1,B):
    r+=v[i]
    max_mean=max(max_mean,r/(i+1))
print(max_mean)

dp=[defaultdict(int) for i in range(N+1)]
dp[0][0]=1

ans=0
for i in range(N):
    for j in reversed(range(1,N+1)):
        for c,k in dp[j-1].items():
            dp[j][c+v[i]]+=k
ans=0
for k in range(A,B+1):
    if floor(max_mean*k)!=ceil(max_mean*k):
        continue
    x=floor(max_mean*k)
    ans+=dp[k][x]
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
V = sorted([int(x) for x in input().split()],reverse=True)
from statistics import mean
from math import comb
maxmean = mean(V[:A])
way = 1
for i in range(1,B+1-A):
    v = V.pop(0)
    if v != maxmean:
        same = i
        break
else:
    same = B-A
if same > 0:
    same += A
    for j in range(A,same):
        way += comb(same, j)
print(maxmean)
print(way)

Submission status: Wrong Answer

Solution code:
import collections
import math

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
d = list(reversed(sorted(v)))
c = collections.Counter(v)

ans = 0
ans_com = 0
for i in range(A, B+1):
  sel = i
  com = 1
  total = 0
  for j in range(len(d)):
    p = c[d[j]]
    com *= math.factorial(p)
    total += d[j] * p
    if sel <= p:
      com /= (math.factorial(sel) * math.factorial(p-sel))
      total -= d[j] * (p - sel)
      break
    sel -= p
  ave = total / i
  if ans == 0:
    ans = ave
    ans_com = int(com)
  elif ans == ave:
    ans_com += int(com)
print(ans)
print(ans_com)

Submission status: Wrong Answer

Solution code:
import collections
import math

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
d = sorted(v)
c = collections.Counter(v)

ans = 0
ans_com = 0
for i in range(B, A-1, -1):
  sel = i
  com = 1
  total = 0
  for j in range(1, len(d)+1):
    p = c[d[-j]]
    com *= math.factorial(p)
    total += d[-j] * p
    if sel <= p:
      com /= (math.factorial(sel) * math.factorial(p-sel))
      total -= d[-j] * (p - sel)
      break
    sel -= p
  ave = total / i
  if ans < ave:
    ans = ave
    ans_com = int(com)
  elif ans == ave:
    ans_com += int(com)
print(ans)
print(ans_com)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

a = 0
for i in range(A):
    a += V[i]
a /= A
print(a)

c = 0

if V[0] != V[A-1]:
    r = 0
    while True:
        r += 1
        if V[A-1-r] != V[A-1]:
            break
    n = 0
    while True:
        if A+n > N-1:
            break
        if V[A+n] != V[A-1]:
            break
        n += 1
    n += r
    c = int(factorial(n) / factorial(r) / factorial(n-r))

else:
    n = 0
    while True:
        n += 1
        if n > N-1:
            break
        if V[n] != V[0]:
            break
    B = min(B, n)
    for i in range(B-A+1):
        c += int(factorial(n) / factorial(A+i) / factorial(n-A-i))

print(c)

Submission status: Wrong Answer

Solution code:
import collections as c
import copy
import math
n,a,b=map(int,input().split())
v0=list(map(int,input().split()))
v=sorted(c.Counter(v0).items(),key=lambda x:-x[0])
v1=copy.deepcopy(v)
v2=copy.deepcopy(v)
avg1,avg2,a1,b1,w1,w2=0,0,a,b,{},{},
while a:
  for i in range(len(v1)):
    for j in range(v1[i][1]):
      avg1+=v1[i][0]
      if v1[i][0] in w1:
        w1[v1[i][0]]+=1
      else:
        w1[v1[i][0]]=1
      a-=1
      if a==0: break
    if a==0: break
avg1=avg1/a1
while b:
  for i in range(len(v2)):
    for j in range(v2[i][1]):
      avg2+=v2[i][0]
      if v2[i][0] in w2:
        w2[v2[i][0]]+=1
      else:
        w2[v2[i][0]]=1
      b-=1
      if b==0: break
    if b==0: break
avg2=avg2/b1
n1,n2=[],[]
for i,j in w1.items():
  t=v0.count(i)
  if t==j:
    n1.append(1)
  else:
    n1.append(math.factorial(t)//(math.factorial(j)*math.factorial(t-j)))
for i,j in w2.items():
  t=v0.count(i)
  if t==j:
    n2.append(1)
  else:
    n2.append(math.factorial(t)//(math.factorial(j)*math.factorial(t-j)))
result=max(avg1,avg2)
print(result)
print([max(n2),max(n1)][result==avg1])

Submission status: Wrong Answer

Solution code:
from math import factorial

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

c = 0

if V[0] == V[-1]:
    print(V[0])
    fn = factorial(N)
    for i in range(B-A+1):
        c += int(fn / factorial(A+i) / factorial(N-A-i))
    print(c)
else:
    a = 0
    v = V[0]
    n = 0
    w_a = True
    w_v = False
    for i in range(N):
        if v == V[i]:
            n += 1
        if v != V[i]:
            if w_v:
                break
            v = V[i]
            n = 1
        if w_a:
            a += V[i]
        if i+1 == A:
            w_a = False
            w_v = True
            a /= i+1
            r = n
    print(a)
    c += int(factorial(n) / factorial(r) /factorial(n-r))
    print(c)

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print format(float(sum(ais[:a]) / float(a)), 'f')

cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1
mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

def g(a, b, ais, cc):
	return 2 ** (min(cc[0]+cc[1], 100000)) - 2 ** (a-1)
print f(cc[0], min(cc[0] + b - a,cc[0] + cc[1])) if ais[0] != ais[a-1] else g(a,b,ais,cc)#(2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print format(float(sum(ais[:a]) / float(a)), 'f')

cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1
mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

def g(a, b, ais, cc):
	return 2 ** (min(cc[0]+cc[1], 100000)) - 2 ** (a-1)
print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else g(a,b,ais,cc)#(2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print format(float(sum(ais[:a]) / float(a)), 'f')

cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1
mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

def g(a, b, ais, cc):
	return 2 ** (min(cc[0]+cc[1], b)) - 2 ** a
print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else g(a,b,ais,cc)#(2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print format(float(sum(ais[:a]) / float(a)), 'f')

cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1
mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else (2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print float(sum(ais[:a]) / float(a))

cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1
mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else (2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print sum(ais[:a]) / float(a)
cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1

mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else (2 ** a) -1

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)

print sum(ais[:a]) / float(a)
cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		if i <= a-1:
			cc[0] += 1
		else:
			cc[1] += 1

mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

print f(cc[0], cc[1] + cc[0]) if ais[0] != ais[a-1] else 2 ** (cc[0] + cc[1])

Submission status: Wrong Answer

Solution code:
import collections
n,a,b = map(int, raw_input().split())
ais = map(int, raw_input().split())
ais.sort(key = lambda x:-x)
print sum(ais[:a]) / float(a)
cc = collections.Counter()
for i in range(n):
	if ais[a-1] == ais[i]:
		cc[0 if i <= a-1 else 1] +=1

mem = {}
def fact(n):
	if n == 0: return 1
	if n not in mem:
		mem[n] = n * fact(n-1)
	return mem[n]

def f(k,n):
	return fact(n) / (fact(k) * fact(n-k))

print f(cc[0], cc[1] + cc[0])