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:
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(num_v) // math.factorial(num_v - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= num_cnt // cnt
        print(max_avg_ptn)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

import operator as op

def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

has = defaultdict(int)

n, a, b = map(int, raw_input().split())

arr = map(int, raw_input().split())

for i in arr:
    has[i] += 1

arr.sort()
arr.reverse()

tempSum = sum(arr[: a])
mean = float(tempSum)/a

sol = arr[: a]
newMean = mean
for i in xrange(b-a):
    newMean = float(tempSum + arr[a + i])/(a + i + 1)
    if newMean > mean:
        mean = newMean
        tempSum += arr[a + i]
        sol.append(arr[a + i])
    else:
        break
    
newHas = defaultdict(int)

for i in sol:
    newHas[i] += 1
ans = 1
for i in set(sol):
    ans *= ncr(has[i], newHas[i])
    
print '%0.8f' %mean
print ans

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        for i in range(1, num_v + 1):
            ans += math.factorial(num_v) // math.factorial(num_v - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= num_cnt // cnt
        print(max_avg_ptn)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

import operator as op
def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

has = defaultdict(int)

n, a, b = map(int, raw_input().split())

arr = map(int, raw_input().split())

for i in arr:
    has[i] += 1

arr.sort()
arr.reverse()

tempSum = sum(arr[: a])
mean = float(tempSum)/a

sol = arr[: a]
newMean = mean
for i in xrange(b-a):
    newMean = float(tempSum + arr[a + i])/(a + i + 1)
    if newMean > mean:
        mean = newMean
        tempSum += arr[a + i]
        sol.append(arr[a + i])
    else:
        break
    
newHas = defaultdict(int)

for i in sol:
    newHas[i] += 1
ans = 1
for i in set(sol):
    ans *= ncr(has[i], newHas[i])
    
print mean
print ans

Submission status: Wrong Answer

Solution code:
_, a, b = map(int, raw_input().split())

v = map(int, raw_input().split())

v.sort(key=lambda x: -x)

s = 0
for i in xrange(a):
    s += v[i]

print '{:.6f}'.format(s / float(a))

# num = v.count(v[a-1])
# print 'num', num
# print v[:a].count(v[a-1])

n = v.count(v[a-1])
k = b - a + v[:a].count(v[a-1])
k = min(k, n)

import operator as op
def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

ways = 0
for i in xrange(k):
    ways += ncr(n, i+1)
print ways

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

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

    ave_max = sum(v[:A]) / A

    onaji = v.count(v[0])

    if onaji < B:
        k = v[:A].count(v[A - 1])
        n = v.count(v[A - 1])
        cnt = binom(n, k)
    else:
        cnt = 0
        n = v.count(v[0])

        for i in range(A, onaji + 1):
            cnt += binom(onaji, i)

    print('{:.8f}'.format(ave_max))
    print(cnt)


def binom(n, k):
    return (factorial(n) // factorial(n - k)) // factorial(k)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())
V = list(sorted(V))
def Mean(S):
    return float(sum(S))/len(S)

def Factorial(n):
    if n == 1:
        return 1.0
    if n == 0:
        return 1.0
    else:
        return n*Factorial(n - 1)

def NCR(n, r):
    return int(Factorial(n)/(Factorial(n - r) * Factorial(r)))

ss = []
mm = 0 # max mean
indices = []
for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = [subset]
        mm = m
        indices = [i]
    if m == mm:
        if subset not in ss:
            ss.append(subset)
            indices.append(i)
print '{0:.06f}'.format(mm)
res = 0
for subset in ss:
    nonredundant = []
    for s in subset:
        if s not in nonredundant:
            nonredundant.append(s)
    prod = 1
    for j in nonredundant:
        prod *= NCR(V.count(j), subset.count(j))
    res += prod
print res

Submission status: Wrong Answer

Solution code:
_, a, b = map(int, raw_input().split())

v = map(int, raw_input().split())

v.sort(key=lambda x: -x)

s = 0
for i in xrange(a):
    s += v[i]

print '{:.6f}'.format(s / float(a))

# num = v.count(v[a-1])
# print 'num', num
# print v[:a].count(v[a-1])

n = v.count(v[a-1])
k = b - a + v[:a].count(v[a-1])
k = min(k, n)

import operator as op
def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

print ncr(n, k)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
r = 1
last = data[a-1]
p = sum(map(lambda x: x == last, data[:a]))
q = sum(map(lambda x: x == last, data[a:b]))
for i in range(p):
  r *= p + q - i
  r //= i + 1    
print(s/k)
print(r)

Submission status: Wrong Answer

Solution code:
import itertools

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

v = map(int, raw_input().split())

resultValue = 0
resultCount = 0

for pcs in range(B - A + 1):
    perm = list(itertools.combinations(v, B + pcs))
    for cand in perm:
        average = float(sum(cand)) / len(cand)
        if resultValue < average:
            resultValue = average
            resultCount = 1
        elif (resultValue - average) == 0.:
            resultCount += 1

print(resultValue)
print(resultCount)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())
V = list(sorted(V))
def Mean(S):
    return float(sum(S))/len(S)

def Factorial(n):
    if n == 1:
        return 1.0
    if n == 0:
        return 1.0
    else:
        return n*Factorial(n - 1)

def NCR(n, r):
    return int(Factorial(n)/(Factorial(n - r) * Factorial(r)))

ss = []
mm = 0 # max mean
indices = []
for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = [subset]
        mm = m
        indices = [i]
    if m == mm:
        if subset not in ss:
            ss.append(subset)
            indices.append(i)
print '{0:.06f}'.format(mm)
res = 0
for (s, index) in zip(ss, indices):
    res += NCR(V.count(V[-index]), s.count(V[-index]))
print res

Submission status: Wrong Answer

Solution code:
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v[:a])) == 1:
    print(v[0])
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            cnt += 1
    ans = 0
    for i in range(a,cnt+1):
        ans += comb(cnt,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
r = 1
last = data[a-1]
p = sum(map(lambda x: x == last, data[:a]))
q = sum(map(lambda x: x == last, data[a:b+1]))
for i in range(p):
  r *= p + q - i
print(s/k)
print(r)

Submission status: Wrong Answer

Solution code:
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v[:a])) == 1:
    print(v[0])
    ans = 0
    for i in range(a,b+1):
        if v[i-1] == v[0]:
            ans += comb(n,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
r = 1
last = data[a-1]
p = sum(map(lambda x: x == last, data[:a]))
q = sum(map(lambda x: x == last, data[a:b+1]))
for i in range(p):
  r *= p + q - i
  r //= i + 1    
print(s/k)
print(r)

Submission status: Wrong Answer

Solution code:
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v)) == 1:
    print(v[0])
    ans = 0
    for i in range(a,b+1):
        ans += comb(n,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

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

    ave_max = sum(v[:A]) / A

    if len(set(v)) == 1:
        cnt = 0

        for k in range(A, B + 1):
            cnt += binom(N, k)
    else:
        k = v[:A].count(v[A - 1])
        n = v.count(v[A - 1])
        cnt = binom(n, k)

    print('{:.8f}'.format(ave_max))
    print(cnt)


def binom(n, k):
    return (factorial(n) // factorial(n - k)) // factorial(k)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
r = 1
if a < n and data[a-1] == data[a]:
  last = data[a]
  p = sum(map(lambda x: x == last, data[:a]))
  q = sum(map(lambda x: x == last, data[a:b+1]))
  for i in range(p):
    r *= p + q - i
    r //= i + 1    
print(s/k)
print(r)

Submission status: Wrong Answer

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
print("{0:.20f}".format(ans))

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

comb = [[0 for i in range(55)] for j in range(55)]
for i in range(55):
	comb[i][i] = 1
	comb[i][0] = 1
	for j in range(1,i):
		comb[i][j] = comb[i-1][j-1] + comb[i-1][j]

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]
print(ans2)

Submission status: Wrong Answer

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

dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]
cnt = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0] = 0
cnt[0][0] = 1

for i in range(N):
    for j in range(N - 1, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i+1][j] = dp[i][j]
        cnt[i+1][j] = cnt[i][j]

        ncost = dp[i][j] + v[i]
        if dp[i+1][j+1] < ncost:
            dp[i+1][j+1] = ncost
            cnt[i+1][j+1] = cnt[i][j]
        elif dp[i+1][j+1] == ncost:
            cnt[i+1][j+1] += cnt[i][j]

maxVal = 0
maxCnt = 0
for i in range(A, B + 1):
    if maxVal < dp[N][i] / i:
        maxVal = dp[N][i] / i
        maxCnt = cnt[N][i]
    if maxVal == dp[N][i] / i:
        maxCnt += cnt[N][i]

print(maxVal)
print(maxCnt)

Submission status: Wrong Answer

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
print(ans)

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

comb = [[0 for i in range(55)] for j in range(55)]
for i in range(55):
	comb[i][i] = 1
	comb[i][0] = 1
	for j in range(1,i):
		comb[i][j] = comb[i-1][j-1] + comb[i-1][j]

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]

print("{0:.20f}".format(ans2))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())

V = list(sorted(V))
ss = None
mm = 0 # max mean
index = 0
def Mean(S):
    return float(sum(S))/len(S)

for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = subset
        mm = m
        index = i
print '{0:.06f}'.format(mm)
print V.count(V[-i])

Submission status: Wrong Answer

Solution code:
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v)) == 1:
    print(v[0])
    ans = 0
    for i in range(a,b+1):
        ans += comb(n,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print(total/a)
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())

V = list(sorted(V))
ss = None
mm = 0 # max mean
index = 0
def Mean(S):
    return float(sum(S))/len(S)

for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = subset
        mm = m
        index = i
print mm
print V.count(V[-i])

Submission status: Wrong Answer

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
print(ans)

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt+=1
		if i >= a-1:
			cnt2+=1

comb = [[0 for i in range(55)] for j in range(55)]

for i in range(55):
	comb[i][i] = 1
	comb[i][0] = 1
	for j in range(1,i):
		comb[i][j] = comb[i-1][j-1] + comb[i-1][j]

ans2 = 0
# print(cnt, cnt2)
if v[0] == v[a-1]:
	for i in range(min(cnt2, b-a+1)):
		num = cnt2 - cnt + i + 1
		# print(cnt, num, comb[cnt][num])
		ans2 += comb[cnt][num]
	print(ans2)
else:
	for i in range(1):
		num = cnt2 - cnt + i + 1
		# print(cnt, num, comb[cnt][num])
		ans2 += comb[cnt][num]
	print(ans2)

Submission status: Wrong Answer

Solution code:
def combination(n, r):
    res = 1
    t = r - 1
    while t >= 0:
        res = res * (n - t) // (r - t)
        t -= 1
    return res

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

v.sort()
v.reverse()

t = 0
for i in range(a):
    t += v[i]
t /= a
print(t)

cnt = 0
if v[0] == v[a-1]:
    candidate = 0
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            candidate += 1
        else:
            break
    for i in range(a, min(b, candidate)+1):
        cnt += combination(candidate, i)
else:
    cnt = 0
    first = 50
    last = 0
    for i in range(n):
        if v[i] == v[a-1]:
            first = min(i, first)
            last = max(i, last)
    candidate = last - first + 1
    for i in range(a-first, b-first):
        cnt += combination(candidate, i)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean

# N個の品物
# A個以上B個以下の個数を選ぶ
N, A, B = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
cnt = 0

# bit全探索
for i in range(1 << len(V)):
    output = []
    for j in range(len(V)):
        if ((i >> j) & 1) == 1:
            output.append(V[j])
            
    # A個以上B個以下ならチェック
    if A <= len(output) <= B:
        # 最大値を更新
        tmp = mean(output)
        #print(output)
        if tmp >= ans:
            # すでに出ていたらカウントを増やす
            if ans == tmp:
                cnt +=1
            # 初登場ならカウントを1にする
            else:
                cnt=1
            ans = tmp

print(float(ans), cnt)

Submission status: Time Limit Exceeded

Solution code:


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

    import itertools
    max_mean=0
    numbers=[]
    V.sort(reverse=True)

    for i in range(A,B+1):
        temp=V[:i]
        temp_mean=sum(temp)/i
        if max_mean<temp_mean:
            max_mean=temp_mean

    for i in range(A, B + 1):
        temp = V[:i]
        temp_mean = sum(temp) / i
        if max_mean == temp_mean:
            numbers.append(i)

    count=0

    for number in numbers:
        for conbination in itertools.combinations(V,number):
            if sum(conbination)/number==max_mean:
                count+=1

    print(max_mean)
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
num = 0
cnt = []

v.sort(reverse=True)
for i in range(A, B+1):
    for j in itertools.combinations(v, i):
        average = sum(j) / i
        ans = max(average, ans)

        cnt .append(average)

print(ans)
print(cnt.count(ans))

Submission status: Time Limit Exceeded

Solution code:
n,a,b,*v=map(int,open(0).read().split())
l=[]
for t in range(1,2**n):
    c=[(t>>s&1)*v[s]for s in range(n)]
    if a<=sum((i!=0)for i in c)<=b:
        l.append(sum(c)/sum((i!=0)for i in c))
print(max(l))
print(l.count(max(l)))

Submission status: Time Limit Exceeded

Solution code:
def combi(n, r):
  if r == 0 or n == r:
    return 1
  return combi(n-1, r-1) + combi(n-1, r)

n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list)/len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
  print(1)
elif max_ave_list[0] != max_ave_list[-1]:
  print(combi(l, m))
else:
  print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

N, A, B = list(map(int, input().split()))
V = np.array(list(map(int, input().split())))
V.sort()
V[:] = V[::-1]

def nCp(n, p):
    return(len(list(itertools.combinations(np.arange(n), p))))

d = V[A-1]
# unless all equal, we only need A
if d == V.max():
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    print(V[:A].mean())
    res = nCp(d_eq_cnt, A)
    res_sum = nCp(d_eq_cnt, A)
    for k in range(1, min(B, d_eq_cnt) + 1 - A):
        res = res * (d_eq_cnt - (A+k-1)) // (A+k)
        res_sum += res
    print(res_sum)
    
    
else:
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    d_lq_cnt = np.count_nonzero(V > d)
    print(V[:A].mean())
    print(nCp(d_eq_cnt, A - d_lq_cnt))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

N, A, B = list(map(int, input().split()))
V = np.array(list(map(int, input().split())))
V.sort()
V[:] = V[::-1]

def nCp(n, p):
    return(len(list(itertools.combinations(np.arange(n), p))))

d = V[A-1]
# unless all equal, we only need A
if d == V.max():
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    print(V[:A].mean())
    print(sum([nCp(d_eq_cnt, k) for k in range(A, min(B,d_eq_cnt)+1)]))
else:
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    d_lq_cnt = np.count_nonzero(V > d)
    print(V[:A].mean())
    print(nCp(d_eq_cnt, A - d_lq_cnt))

Submission status: Time Limit Exceeded

Solution code:
import itertools

def mymap(groups):
    y = []
    for group in groups:
        for com in group:
            y.append(sum(com) / len(com))
    return y

header = input().split()
N,A,B = int(header[0]),int(header[1]),int(header[2])
items = input().split()
items = [int(x) for x in items]
patterns = []
ans = []
#enum
for i in range(A,B+1):
    patterns.append(list(itertools.combinations(items,i)))

AVEs = mymap(patterns)
print(max(AVEs))
print(AVEs.count(max(AVEs)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, a, b = map(int, input().split())
# v[0] ~ v[n-1]
v = list(map(int, input().split()))

ma = 0
ans = 0
for i in range(a, b + 1):
    comb_v = itertools.combinations(v, i)

    while True:
        try:
            ave = sum(next(comb_v)) / i
            if ave > ma:
                ma = ave
                ans = 1
            elif ave == ma:
                ans += 1

        except StopIteration:
            break

print(format(ma, ".6f"))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import factorial

def solve():
    N, A, B = map(int, input().split())
    v = [int(i) for i in input().split()]

    h1, c1 = half_rekkyo(N, v, 0, N // 2)
    h2, c2 = half_rekkyo(N, v, N // 2, N - N //2)

    max_ave = 0
    cnt = 0

    for i in range(len(h1)):
        for j in range(len(h2)):
            if A <= i + j <= B:
                tot = h1[i] + h2[j]
                ave = tot / (i + j)

                if ave > max_ave:
                    cnt = c1[i] * c2[j]
                    max_ave = ave
                elif ave == max_ave:
                    cnt += c1[i] * c2[j]

    print(max_ave)
    print(cnt)

def half_rekkyo(N, v, s, m):
    max_vs = [0] * (m + 1)
    nums = [0] * (m + 1)

    for cmb in range(2**m):
        # print(bin(cmb))
        value = 0
        cnt = 0

        for i in range(m):
            if cmb & (1 << i):
                value += v[s + i]
                cnt += 1

        # print(value, cnt)

        if value == max_vs[cnt]:
            nums[cnt] += 1
        elif value > max_vs[cnt]:
            nums[cnt] = 1
            max_vs[cnt] = value

    return max_vs, nums

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

def comb(n,k):
    return math.factorial(n)//math.factorial(k)//math.factorial(n-k)
    


n,a,b=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
v1=sorted(v)
v1.reverse()
#print(v1)
sum=0
for i in range(a):
    sum+=v1[i]
result=sum/a
print(result)

ctmax=v1.count(v1[0])
if a<ctmax and b<=ctmax:
    ct=0
    for i in range(a,b+1):
        ct+=comb(ctmax,i)
    print(ct)

elif a<ctmax and ctmax<b:
    ct=0
    for i in range(a,ctmax+1):
        ct+=comb(ctmax,i)
    print(ct)
else:
    ct=0
    l=list(itertools.combinations(v1,a))
    #print(l)
    for j in l:
        flag=0
        for k in range(a):
            if v1[k]!=j[k]: flag=1
        if flag==0:
            ct+=1
            #print(j)
    print(ct)

Submission status: Time Limit Exceeded

Solution code:
import math, itertools
N,A,B=[int(i) for i in input().split()]
v=input().split()
max = 0
count = 0
for i in range(A,B+1):
	c = list(itertools.combinations(v,i))
	for item in c:
		avgv = 0
		l = len(item)
		for k in item:
			avgv += int(k)
		avgv /= l
		if max <= avgv:
			if avgv - max <= 0.000001:
				count += 1
			else:
				max = avgv
				count = 1
print(max)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

v = map(int, raw_input().split())

resultValue = 0
resultCount = 0

for pcs in range(A, B + 1):
    perm = list(itertools.combinations(v, pcs))
    for cand in perm:
        average = float(sum(cand)) / len(cand)
        if resultValue < average:
            resultValue = average
            resultCount = 1
        elif (resultValue - average) == 0.:
            resultCount += 1

print(resultValue)
print(resultCount)

Submission status: Time Limit Exceeded

Solution code:
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = 0
for i in range(a,b+1):
    s = sum(v[:i])*1.0/i
    if s > res1:
        res1 = s
print res1
res2 = 0
for i in range(a,b+1):
    for j in itertools.combinations(v,i):
        if sum(j)==res1*i:
            res2 +=1
print res2

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,A,B=map(int,raw_input().split(' '))
sina=map(int,raw_input().split(' '))
sina.sort()
sina=sina[::-1]

max_ave=0
for i in range(A,B+1):
    ave=sum(sina[0:i])*1.0/i
    if ave>max_ave:
        max_ave=ave
    
print max_ave

c=0
for i in range(A,B+1):
    for l in list(itertools.combinations(sina,i)):
        if sum(l)*1.0/i==max_ave:
            c+=1

print c

Submission status: Time Limit Exceeded

Solution code:
import itertools


n,a,b=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
index=list(range(n))


result=0
ct=0
for i in range(a,b+1):
    l=list(itertools.combinations(index,i))
    for j in l:
        sum=0
        for k in j:
            sum+=v[k]
        if result<(sum/i):
            result=sum/i
            ct=1
        elif result==(sum/i):
            ct+=1

print(result)
print(ct)

Submission status: Accepted

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[a - 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[a - 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)