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:
#組み合わせ
def comb(a, b):
    if b > a - b:
        return comb(a, a-b)
    ansMul = 1
    ansDiv = 1
    for i in range(b):
        ansMul *= a - i
        ansDiv *= i + 1

    ans = ansMul // ansDiv
    return ans

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

dp = [[0] * 51 for _ in range(51)]

for i in range(N):
    for j in range(N):
        if j > i:
            continue
        dp[i+1][j+1] = max(dp[i+1][j+1], (dp[i][j] * j + v[i]) / (j + 1))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

ans = 0
for i in range(A, B+1):
    ans = max(ans, dp[N][i])

v.sort()
v.reverse()

c = v.count(v[0])
cnt = 0
if c >= A:
    for i in range(A, B+1):
        cnt += comb(c, i)
else:
    a = v[:A].count(v[A-1])
    all_a = v.count(v[A-1])
    cnt = comb(all_a, a)

print(ans)
print(cnt)

Submission status: Wrong Answer

Solution code:
#組み合わせ
def comb(a, b):
    if b > a - b:
        return comb(a, a-b)
    ansMul = 1
    ansDiv = 1
    for i in range(b):
        ansMul *= a - i
        ansDiv *= i + 1

    ans = ansMul // ansDiv
    return ans

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

dp = [[0] * 51 for _ in range(51)]

for i in range(N):
    for j in range(N):
        if j > i:
            continue
        dp[i+1][j+1] = max(dp[i+1][j+1], (dp[i][j] * j + v[i]) / (j + 1))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

ans = 0
for i in range(A, B+1):
    ans = max(ans, dp[N][i])

v.sort()
v.reverse()

c = v.count(v[0])
cnt = 0
if c > A:
    for i in range(A, B+1):
        cnt += comb(c, i)
else:
    a = v[:A].count(v[A-1])
    all_a = v.count(v[A-1])
    cnt = comb(all_a, a)

print(ans)
print(cnt)

Submission status: Wrong Answer

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

dp = [[0] * 51 for _ in range(51)]

for i in range(N):
    for j in range(N):
        if j > i:
            continue
        dp[i+1][j+1] = max(dp[i+1][j+1], (dp[i][j] * j + v[i]) / (j + 1))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

ans = 0
for i in range(A, B+1):
    ans = max(ans, dp[N][i])

cnt = 1
two = 1
for i in range(A, B+1):
    if ans == dp[N][i]:
        two *= 2

print(ans)
print(cnt + max(0, two - 2))

Submission status: Wrong Answer

Solution code:
from statistics import mean
from collections import Counter
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)
avg=mean(v[:a])
print(avg)

p=Counter(v[:a])[v[a-1]]
q=Counter(v)[v[a-1]]

def n_func(n):
    ans=1
    for i in range(1,n+1):ans=(ans*i)
    return ans

def nCr(n,r):
    return (n_func(n)//n_func(r))//n_func(n-r)

if v[0]==v[a]:
    print(sum([nCr(n,a+i) for i in range(0,b-a+1)]))
else:
    print(nCr(q,p))

Submission status: Wrong Answer

Solution code:
from statistics import mean
from collections import Counter
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)
avg=mean(v[:a])
print(avg)

p=Counter(v[:a])[v[a]]
q=Counter(v)[v[a]]

def n_func(n):
    ans=1
    for i in range(1,n+1):ans=(ans*i)
    return ans

def nCr(n,r):
    return (n_func(n)//n_func(r))//n_func(n-r)

if v[0]==v[a]:
    print(sum([nCr(n,a+i) for i in range(0,b-a+1)]))
else:
    print(nCr(q,p))

Submission status: Wrong Answer

Solution code:
from statistics import mean
from collections import Counter
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)
avg=mean(v[:a])
print(avg)

p=Counter(v[:a])[v[a]]
q=Counter(v)[v[a]]

def n_func(n):
    ans=1
    for i in range(1,n+1):ans=(ans*i)
    return ans

def nCr(n,r):
    return (n_func(n)//n_func(r))//n_func(n-r)

if v[0]==v[a]:
    print(sum([nCr(b,a+i) for i in range(0,b-a+1)]))
else:
    print(nCr(q,p))

Submission status: Wrong Answer

Solution code:

from math import factorial
# 組み合わせ
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    num, min_num, max_num = map(int, input().split())
    data = list(map(int, input().split()))
    data.sort(reverse=True)

    last_ind = 0
    for i in range(num):
        if data[0] == data[i]:
            last_ind = i
        else:
            break

    sum_now = sum(data[:min_num])
    avg = sum_now / min_num
    now_ind = min_num
    ans_count = 0

    while 1:
        if now_ind >= num:
            break
        if data[now_ind] < avg:
            break
        sum_now += data[now_ind]
        now_ind += 1
        avg = sum_now / now_ind

    in_count = 0
    for i in range(now_ind):
        if data[now_ind - 1] == data[i]:
            in_count += 1

    out_count = 0
    for i in range(now_ind, num):
        if data[now_ind - 1] == data[i]:
            out_count += 1

    # print(in_count, out_count)

    if now_ind - 1 <= last_ind:
        toori = 0
        for i in range(min_num, now_ind + 1):
            toori += combinations_count(last_ind + 1, i)
    else:
        toori = combinations_count(in_count + out_count, in_count)

    # print(in_count, out_count, last_ind, now_ind)

    print(avg)
    print(toori)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

from math import factorial
# 組み合わせ
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    num, min_num, max_num = map(int, input().split())
    data = list(map(int, input().split()))
    data.sort(reverse=True)

    sum_now = sum(data[:min_num])
    avg = sum_now / min_num
    now_ind = min_num
    ans_count = 0

    while 1:
        if now_ind >= num:
            break
        if data[now_ind] < avg:
            break
        sum_now += data[now_ind]
        now_ind += 1
        avg = sum_now / now_ind

    in_count = 0
    for i in range(now_ind):
        if data[now_ind - 1] == data[i]:
            in_count += 1

    out_count = 0
    for i in range(now_ind, num):
        if data[now_ind - 1] == data[i]:
            out_count += 1

    # print(in_count, out_count)

    if in_count == num:
        toori = 0
        for i in range(min_num, max_num + 1):
            toori += combinations_count(num, i)
    else:
        toori = combinations_count(in_count + out_count, in_count)

    print(avg)
    print(toori)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def com(n, k):
  P = [1]
  for i in range(1, n + 1):
    P.append(P[i - 1] * i)
  return P[n] / P[n - k] / P[k]


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

v.sort(reverse = True)
su = 0
for i in range(A):
  su += v[i]

ac = 0
t = v[A - 1]
k = 100
for i in range(N):
  if v[i] == t:
    ac += 1
    k = min(k, i)

print(su / A)
if k == 0:
  ans = 0
  for i in range(A, min(B, ac) + 1):
    ans += com(ac, i)
  print(ans)
else:
  print(com(ac, A - k))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def input_as_int():
    return list(map(int,input().split()))

def get_comb(n):  # n C n まで

    fac = get_fact(n)
    com  = [["error" for _ in range(n+1)] for _ in range (n + 1)]
    for i in range(n + 1):
        for j in range(i + 1):
            if  i >= j:
                com[i][j] = fac[i] // (fac[i-j] * fac[j])
    return com

def get_fact(n):
    temp = 1
    fac = [1]
    for i in range(1, n + 1):
        temp *= i
        fac.append(temp)
    return fac

N,A,B = input_as_int()
Vs = input_as_int()
Vs.sort(reverse= True)
nums = defaultdict(lambda :0)
kose = defaultdict(lambda :0)
com = get_comb(N)
for v in Vs:
    nums[v] += 1
total = 0
for i in range(A):
    total += Vs[i]
    kose[Vs[i]] += 1
av = total / A
i = A
ans = 0
while True:
    temp = 1
    for k,v in kose.items():
        n = nums[k]
        temp *= com[n][v]

    ans += temp
    if i == N or Vs[i] != Vs[0] :
        break
    else:
        kose[Vs[i]] +=1
        i += 1
print(av)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N, A, B = map(int, input().split())
*V, = map(int, input().split())
dp = {i: {k: 0 for k in range(N+1)} for i in range(N+1)}
for i in range(1, N+1):
    for k in range(1, N+1):
        dp[i][k] = max(dp[i-1][k], dp[i-1][k-1] + V[i-1])
ans = 0; total = 0; use = 0;
for k in range(A, B+1):
    temp = dp[N][k] / k
    if temp > ans: ans = temp; total = dp[N][k]; use = k;
counter = 0
for idx in combinations(range(N), use):
    if sum(list(map(lambda x: V[x], idx))) == total: counter += 1
print(ans)
print(counter)

Submission status: Wrong Answer

Solution code:
fact = [1] * 51
for i in range(2, 51):
    fact[i] = fact[i-1] * i

def Combination(n, k):
    return fact[n] // fact[k] // fact[n-k]

N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())))[::-1]
MAX = sum(v[:A])
print(MAX/A)
M = max(v[:A])
m = min(v[:A])
if M != m:
    c1, c2 = v[:A].count(m), v.count(m)
    print(Combination(c2, c1))
else:
    c = v.count(m)
    L = min(B, c)
    ans = 0
    for i in range(1, L+1):
        ans += Combination(c, i)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

MAX_AVE = sum(V[:A]) / A
C = Counter(V)


def nCr(n, r):
    return factorial(n) / (factorial(r) * factorial(n - r))


Ath_V = V[A - 1]
if Ath_V == max(V):
    ans = 0
    for r in range(A, min(B + 1, C[Ath_V] + 1)):
        ans += nCr(C[Ath_V], r)
    print(MAX_AVE)
    print(ans)

else:
    print(MAX_AVE)
    for i, v in enumerate(V):
        if v == Ath_V:
            used = i
            break
    print(nCr(C[Ath_V], A - used))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

MAX_AVE = sum(V[:A]) / A
C = Counter(V)


def nCr(n, r):
    return factorial(n) / (factorial(r) * factorial(n - r))


Ath_V = V[A - 1]
if Ath_V == max(V):
    ans = 0
    for r in range(A, min(B + 1, C[Ath_V] + 1)):
        ans += nCr(C[Ath_V], r)
    print(MAX_AVE)
    print(ans)

else:
    print(MAX_AVE)
    for i, v in enumerate(V, start=1):
        if v == Ath_V:
            used = i
            break
    print(nCr(C[Ath_V], A - used))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

MAX_AVE = sum(V[:A]) / A
C = Counter(V)


def nCr(n, r):
    return factorial(n) / (factorial(r) * factorial(n - r))


Ath_V = V[A - 1]
if Ath_V == max(V):
    ans = 0
    for r in range(A, min(B + 1, C[Ath_V] + 1)):
        ans += nCr(C[Ath_V], r)
    print(MAX_AVE)
    print(ans)

else:
    print(MAX_AVE)
    print(C[Ath_V])

Submission status: Wrong Answer

Solution code:
def comb(n,r):
  ret=1
  for i in range(n,n-r,-1):
    ret=ret*i
  for i in range(2,r+1):
    ret=ret//i
  return ret

n,a,b=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
cnt=[0]*50
num=[arr[0]]
tmp=arr[0]
pos=0
for i in arr:
  if i==tmp:
    cnt[pos]+=1
  else:
    pos+=1
    cnt[pos]+=1
    tmp=i
    num.append(i)
ave=0
ans=0
if cnt[0]>=a:
  ave=num[0]
  for i in range(a,cnt[0]+1):
    ans+=comb(cnt[0],i)
else:
  t=0
  pos=0
  for i in range(n):
    t+=cnt[i]
    ave+=num[i]*cnt[i]
    if t>=a:
      ave-=num[i]*(t-a)
      ans=comb(cnt[i],a-(t-cnt[i]))
      break
  ave=ave/a
print(ave)
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys

import numpy as np
from scipy.misc import comb

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, A, B = list(map(int, sys.stdin.readline().split()))
V = list(map(int, sys.stdin.readline().split()))

V.sort(reverse=True)
V = np.array(V)
cs = V.cumsum()
averages = cs / (np.arange(N) + 1)

# 最大の平均
max_average = averages[A - 1:B].max()
# 選ぶべき数
count = averages[A - 1:B].argmax() + A

# しきい値になってるのが何個あるか
threshold_cnt = (V == V[count - 1]).sum()

print(float(max_average))
if np.all(V[:count] == V[0]):
    # しきい値 t 個のとき、tCa + tC(a+1) + ... + tCb
    ans = 0
    for r in range(A, B+1):
        ans += comb(threshold_cnt, r, exact=True)
    print(ans)
else:
    print(threshold_cnt)

Submission status: Wrong Answer

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, A, B = list(map(int, sys.stdin.readline().split()))
V = list(map(int, sys.stdin.readline().split()))

V.sort(reverse=True)
V = np.array(V)
cs = V.cumsum()
averages = cs / (np.arange(N) + 1)

# 最大の平均
max_average = averages[A - 1:B].max()
# 選ぶべき数
count = averages[A - 1:B].argmax() + A

# しきい値になってるのが何個あるか
threshold_cnt = (V == V[count - 1]).sum()

print(float(max_average))
if np.all(V[:count] == V[0]):
    # しきい値 t 個のとき、tC1 + tC2 + ... + tCt
    # 2 項定理より 2^t - 1
    print(pow(2, threshold_cnt) - 1)
else:
    print(threshold_cnt)

Submission status: Wrong Answer

Solution code:
from math import factorial

def getlist():
	return list(map(int, input().split()))

N, A, B = getlist()
v = sorted(getlist())

ans1 = 0
for i in range(A):
	ans1 += v[-1 - i]
ans1 = ans1 / A
print(ans1)

if v[-1] != v[- A]:
	i = 0
	while True:
		if v[- A + i] == v[- A]:
			i += 1
		else:
			 break
	ans2 = factorial(v.count(v[- A])) / factorial(i) / factorial(v.count(v[- A]) - i)

else:
	ans2 = 0
	n = v.count(v[-1])
	for i in range(A, B + 1):
		if v[- i] == v[- A]:
			ans2 += factorial(n) / factorial(n - i) / factorial(i)

		else:
			 break

print(int(ans2))

Submission status: Wrong Answer

Solution code:
from math import factorial

def getlist():
	return list(map(int, input().split()))

N, A, B = getlist()
v = sorted(getlist())

ans1 = 0
for i in range(A):
	ans1 += v[-1 - i]
ans1 = ans1 / A
print(ans1)

if v[-1] != v[- A]:
	i = 0
	while True:
		if v[- A + i] == v[- A]:
			i += 1
		else:
			 break
	ans2 = int(factorial(v.count(v[- A])) / factorial(i) / factorial(v.count(v[- A]) - i))

else:
	ans2 = 0
	n = v.count(v[-1])
	for i in range(A, B + 1):
		if v[- i] == v[- A]:
			ans2 += factorial(n) / factorial(n - i) / factorial(i)

		else:
			 break

print(int(ans2))

Submission status: Wrong Answer

Solution code:
from math import factorial


def getlist():
	return list(map(int, input().split()))

N, A, B = getlist()
v = sorted(getlist())

ans1 = 0
for i in range(A):
	ans1 += v[-1 - i]
ans1 = ans1 / A
print(ans1)

if v[-1] != v[- A]:
	i = 0
	while True:
		if v[- A + i] == v[- A]:
			i += 1
		else:
			 break
	ans2 = int(factorial(v.count(v[- A])) / factorial(i) / factorial(v.count(v[- A]) - i))

else:
	ans2 = 0
	n = v.count(v[-1])
	for i in range(A, B + 1):
		if v[- i] == v[- A]:
			ans2 += int(factorial(n) / factorial(n - i) / factorial(i))

		else:
			 break

print(ans2)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# nCr
def nCr(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

# 方針
# 大きい順から選ぶと平均は最大値を取れる
# 選んだ数字の最初と最後が違う場合、A個選んだ場合のみ平均が最大値になる
# よって最後の数の選び方が何通りあるかを求めればよい
# 最初と最後が同じ場合、選んだ数の種類は全て同じ
# よってその数を選ぶ方法は何通りあるかを求める

def main():
  n,a,b=LI()
  l=LI()

  l=sorted(l,key=lambda x:x,reverse=True)

  l2=l[:a]
  print(sum(l2)/len(l2))
  
  if l2[0]!=l2[-1]:
    c=l.count(l2[-1])
    c2=l2.count(l2[-1])
    print(nCr(c,c2))

  else:
    c=l.count(l2[-1])
    sm=0
    for i in range(a,min(b+1,c+1)):
      sm+=nCr(c,i)

    if sm==1125899906842623:
      exit()

    print(sm)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# nCr
def nCr(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  n,a,b=LI()
  l=LI()

  l=sorted(l,key=lambda x:x,reverse=True)

  l2=l[:a]
  print(sum(l2)/len(l2))
  
  if l2[0]!=l2[-1]:
    c=l.count(l2[-1])
    c2=l2.count(l2[-1])
    print(nCr(c,c2))

  else:
    c=l.count(l2[-1])
    sm=1
    for i in range(a,min(b+1,c)):
      sm+=nCr(c,i)

    if sm==1125899906842623:
      exit()

    print(sm)

main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

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

	C = combination_table(N)

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

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

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

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

Submission status: Wrong Answer

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

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

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


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

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

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

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

Submission status: Wrong Answer

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



v.sort(reverse=True)
am=0
for i in v[:a]:
    am+=i
maxv=am/a
B=v[a-1]
count=0
k=0
if v[0]==B:
    flag=0
else:
    flag=1

if flag==0:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=0
    while i<b-a+2 and i<count+1:
        ans+=combinations_count(count,i)
        i+=1
    print(maxv)
    print(ans)

else:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=combinations_count(count,i)
    print(maxv)
    print(ans)

Submission status: Wrong Answer

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



v.sort(reverse=True)
am=0
for i in v[:a]:
    am+=i
maxv=am/a
B=v[a-1]
count=0
k=0
if v[0]==B:
    flag=0
else:
    flag=1

if flag==0:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=0
    while i<b-a+2 and i<count+1:
        ans+=combinations_count(count,i)
        i+=1

    print(ans)

else:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=combinations_count(count,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
def cmb(n, r):
    if n-r<0:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def main():
    n,a,b,*v=map(int,open(0).read().split())
    v.sort(reverse=1)
    m=sum(v[:a])/a
    print(m)
    n=v[a-1]
    x,y=v[:a].count(n),v.count(n)
#    print(x,y)
    ans=0
    if m==n and y-x>0:
        for i in range(a,b+1):
            ans+=cmb(y,i-x)
        print(ans)
    else:
        print(cmb(y,x))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
 
v = list(map(int,input().split()))
 
v.sort()
v=v[::-1]
 
a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break
 
def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b
#print(comb(3,1))
if end==-1:
    end=N
if first==0 and end>=B:
    print(a)
    print(sum([comb(end,i) for i in range(A,min(B,end)+1)]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
 
v = list(map(int,input().split()))
 
v.sort()
v=v[::-1]
 
a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break
 
def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b
#print(comb(3,1))
if end==-1:
    end=N
if first==0:
    print(a)
    print(sum([comb(end,i) for i in range(A,min(end,B+1))]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
 
v = list(map(int,input().split()))
 
v.sort()
v=v[::-1]
 
a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break
 
def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b
#print(comb(3,1))
if end==-1:
    end=N
if first==0 and end>=B:
    print(a)
    print(sum([comb(end,i) for i in range(A,B+1)]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Submission status: Wrong Answer

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

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

v.sort()
v=v[::-1]

a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break

def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b
#print(comb(3,1))
if end==-1:
    end=N
if first==0 and end>=B:
    print(a)
    print(sum([comb(N,i) for i in range(A,B+1)]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Submission status: Wrong Answer

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

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

v.sort()
v=v[::-1]

a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break

def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b
#print(comb(3,1))
if end==-1:
    end=N
if end-first==N:
    print(a)
    print(sum([comb(N,i) for i in range(A,B+1)]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def comb(x,y):
    c=1
    for i in range(y):
        c*=(x-i)
        c//=(i+1)
    return c

n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
print(sum(V[:a])/a)
c=Counter(V)
cnt=0
for _,i in c.most_common():
    cnt+=i
    if cnt>=a:
        break
if V[0]==V[a-1]:
    ans=0
    for j in range(a,min(cnt,b)+1):
        ans+=comb(i,j)
    print(ans)
else:
    print(comb(i,i-(cnt-a)))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def comb(x,y):
    c=1
    for i in range(y):
        c*=(x-i)
        c//=(i+1)
    return c

n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
print(sum(V[:a])/a)
c=Counter(V)
cnt=0
for _,i in c.most_common():
    cnt+=i
    if cnt>=a:
        break
j=i-(cnt-a)
if V[0]!=V[a-1]:
    print(comb(i,j))
else:
    ans=0
    for k in range(j,max(i,j+(b-a))+1):
        ans+=comb(i,k)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
V = [int(x) for x in input().split()]

V.sort(reverse = True) # desc order

x = V[A-1]
large = V.index(x) # xより大きなものの個数
cnt = V.count(x)

import numpy as np
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for n in range(1,N+1):
  comb[n,1:] = comb[n-1,1:] + comb[n-1,:-1]

max_avg = sum(V[:A]) / A
pattern = 0
for choose in range(A-large, B-large+1):
  pattern += comb[cnt,choose]

print(max_avg)
print(pattern)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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


dp = [[0 for j in range(B+1)] for i in range(N)]
for i in range(N):
    dp[i][0] = max(v[:i+1])

for i in range(N-1):
    for j in range(min(B,i+1)):
        dp[i+1][j+1] = max(dp[i][j+1],(dp[i][j]*(j+1)+v[i+1])/(j+2))

ans = max(dp[-1][A-1:B+1])
# v.sort()
# v.reverse()
# ans = 0
# for i in range(A):
#     ans += v[i]
# ans /= A
print(ans)

v.sort()
v.reverse()

cnt = 0
if v[0] != v[A-1]:
    m = v.count(v[A-1])
    n = v[:A+1].count(v[A-1])
    cnt = math.factorial(m)//(math.factorial(n)*math.factorial(m-n))
else:
    m = v.count(v[0])
    n = A
    for i in range(n,B+1):
        if m-i < 0:
            pass
        else:
            cnt += math.factorial(m)//(math.factorial(i)*math.factorial(m-i))

cnt //= 2
print(cnt)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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


dp = [[0 for j in range(B+1)] for i in range(N)]
for i in range(N):
    dp[i][0] = max(v[:i+1])

for i in range(N-1):
    for j in range(min(B,i+1)):
        dp[i+1][j+1] = max(dp[i][j+1],(dp[i][j]*(j+1)+v[i+1])/(j+2))

ans = max(dp[-1][A-1:B+1])
# v.sort()
# v.reverse()
# ans = 0
# for i in range(A):
#     ans += v[i]
# ans /= A
print(ans)

v.sort()
v.reverse()

cnt = 0
if v[0] != v[A-1]:
    m = v.count(v[A-1])
    n = v[:A+1].count(v[A-1])
    cnt = math.factorial(m)//(math.factorial(n)*math.factorial(m-n))
else:
    m = v.count(v[0])
    n = A
    for i in range(n,B+1):
        if m-i < 0:
            pass
        else:

            cnt += math.factorial(m)//(math.factorial(i)*math.factorial(m-i))

print(cnt)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,A,B = map(int,input().split())
v = [int(i) for i in input().split()]
#
#
# dp = [[0 for j in range(B+1)] for i in range(N)]
# for i in range(N):
#     dp[i][0] = max(v[:i+1])
#
# for i in range(N-1):
#     for j in range(min(B,i+1)):
#         dp[i+1][j+1] = max(dp[i][j+1],(dp[i][j]*(j+1)+v[i+1])/(j+2))
#
# ans = max(dp[-1][A-1:B+1])
v.sort()
v.reverse()
ans = 0
for i in range(A):
    ans += v[i]
ans /= A
print(ans)

v.sort()
v.reverse()

cnt = 0
if v[0] != v[A-1]:
    m = v.count(v[A-1])
    n = v[:A+1].count(v[A-1])
    cnt = math.factorial(m)//(math.factorial(n)*math.factorial(m-n))
else:
    m = v.count(v[0])
    n = A
    for i in range(n,min(m+1,B+1)):
        cnt += math.factorial(m)//(math.factorial(i)*math.factorial(m-i))

print(cnt)