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: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, A, B = li_input()
    V = sorted(li_input(), reverse=True)
    D = collections.defaultdict(lambda: 0)

    avg = -1
    ans = 0

    for v in V:
        D[v] += 1

    for e in range(A, B+1):
        avg_ = sum(V[:e]) / e

        if avg == -1 or avg_ == avg:
            n = D[V[e-1]]
            r = V[:e].count(V[e-1])
            ans += comb(n, r)
            avg = avg_

    print(avg)
    print(ans)

main()

Submission status: Accepted

Solution code:
import collections
import math 
N,A,B = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
print(sum(x[-A:])/A)
c = collections.Counter(x)
s=0
ans=0
for i in range(N-1,0,-1):
    t = s
    s+=c.get(x[i])
    if s>=A and t ==0:
        #print(c.get(x[i]))
        for j in range(A,min(c.get(x[i]),B)+1):
            #print(ans)
            ans+=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-j)*math.factorial(j))
        break
    elif s>=A:
        ans=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-(A-t))*math.factorial(A-t))
        break
print(int(ans))

Submission status: Accepted

Solution code:
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        if r>n: break
        ans += comb(n, r)
else:
    #print(n, r)
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_max = max(v_arr)
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 # 何個とるか
p_prev = 0

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[i-1] * i)

def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return factorial[n] / (factorial[k] * factorial[n - k])

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    p_prev = p
    
ave /= A
print(ave)
        
last_count_all = 0 # 何個のうちから
for v in v_arr:
    if v == p:
        last_count_all += 1

# print(last_count_all, last_count)
ans = 0
if p == v_max:
    for i in range(min(last_count_all, B) - last_count + 1):
        ans += combination(last_count_all, last_count + i)
else:
    ans = combination(last_count_all, last_count)
print(int(ans))

Submission status: Accepted

Solution code:
from collections import OrderedDict
from math import factorial


def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
counter = OrderedDict()
for i in range(N):
    if v[i] in counter:
        counter[v[i]][0] += 1
    else:
        counter[v[i]] = [1, i + 1]
average = []
for i in range(A, B + 1):
    ave = sum(v[:i]) / i
    num = comb(counter[v[i - 1]][0], i - counter[v[i - 1]][1] + 1)
    average.append([ave, num])
average.sort(key=lambda x: -x[0])
M_arv = average[0][0]
ans = 0
for item in average:
    if item[0] == M_arv:
        ans += item[1]
    else:
        break
print('{:.6f}'.format(M_arv))
print(int(ans))

Submission status: Accepted

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

v.sort()
v.reverse()

print("{:.7f}".format(sum(v[0: A]) / A))

cnt = 0
target = v[A - 1]
first = -1

for i, vv in enumerate(v):
    if vv == target:
        if first == -1:
            first = i
        cnt += 1

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

if first == 0:
    # cnt C A + ... + cnt C min(cnt, B)
    ans = 0
    for i in range(A, min(cnt, B) + 1):
        ans += comb(cnt, i)
    print(ans)
else:
    print(comb(cnt, A - first))

Submission status: Accepted

Solution code:
from collections import Counter as c
from functools import lru_cache,reduce

@lru_cache()
def comb(a,b):
    if not a>=b>=0:
        return 0
    if b==1:
        return a
    elif b==0:
        return 1
    return comb(a-1,b)+comb(a-1,b-1)

n,a,b=map(int,input().split())
v=sorted(map(int,input().split()))[::-1]

c1=c(v)
ans1=sum(v[:a])
ans2=0

for i in range(a,b+1):
    if ans1*i!=sum(v[:i])*a:break
    c2=c(v[:i])
    ans2+=reduce(lambda x,y:x*y,map(lambda x:comb(c1[x],c2[x]),c2.keys()))

print(ans1/a,ans2,sep="\n")

Submission status: Accepted

Solution code:
import math

def func(n, a, b, v):
    v.sort()
    v.reverse()
    target = v[a - 1]
    count = 0
    innerCount = 0
    for i in range(n):
        if v[i] == target:
            if i < a:
                innerCount += 1
            count += 1
    # aつすべてがv[i] == targetの場合
    if v[0] == target:
        out = 0
        for i in range(a, min(count, b) + 1):
            out += math.factorial(count) \
                   // (math.factorial(count - i)
                       * math.factorial(i))
        print(sum(v[:a])/a)
        print(out)
    elif v[a-1] == v[a]:
        print(sum(v[:a])/a)
        print(math.factorial(count)
              // (math.factorial(count - innerCount)
                  * math.factorial(innerCount)))
    else:
        print(sum(v[:a])/a)
        print(1)
n, a, b = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
func(n, a, b, v)
"""
func(5, 2, 2, [5, 4, 3, 2, 1])
print()
func(4, 2, 3, [20, 10, 10, 10])
print()
func(5, 1, 5, [1000000000000000, 999999999999999, 999999999999998, 999999999999997, 999999999999996])
print()
func(50, 1, 50, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
# print("func({}, {}, {}, {})".format(n, a, b, v))
"""

Submission status: Accepted

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

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

cnts = []
cnt = 0
res = None
for i in range(N):
    if res is None or V[i] != res:
        if res is not None:
            cnts.append(cnt)
        cnt = 1
        res = V[i]
    else:
        cnt += 1
cnts.append(cnt)
fac = [1, 1]
for i in range(2, 51):
    fac.append(i*fac[-1])

if cnts[0] >= A:
    ans = 0
    for i in range(A, min(B, cnts[0])+1):
        ans += fac[cnts[0]]//fac[i]//fac[cnts[0]-i]
else:
    ans = 1
    for cnt in cnts:
        if cnt <= A:
            A -= cnt
            B -= cnt
        else:
            ans *= fac[cnt]//fac[A]//fac[cnt-A]
print(m)
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

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

cnts = []
cnt = 0
res = None
for i in range(N):
    if res is None or V[i] != res:
        if res is not None:
            cnts.append(cnt)
        cnt = 1
        res = V[i]
    else:
        cnt += 1
cnts.append(cnt)
fac = [1, 1]
for i in range(2, 51):
    fac.append(i*fac[-1])

if cnts[0] >= A:
    ans = 0
    for i in range(A, min(B, cnts[0])+1):
        ans += fac[cnts[0]]//fac[i]//fac[cnts[0]-i]
else:
    ans = 1
    for cnt in cnts:
        if cnt <= A:
            A -= cnt
            B -= cnt
            ans *= cnt
        else:
            ans *= fac[cnt]//fac[A]//fac[cnt-A]
print(m)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

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

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


N, a, b = inpl()
array = inpl()
value = Counter(array)
array.sort(reverse=True)
ans = {}
sum_a = 0
kosuu = 0
last = -1
# print("koko")
for i, num in enumerate(array):
    # print(i, num)
    sum_a += num
    if last != num:
        kosuu = 1
        last = num
    else:
        kosuu += 1
    if a <= i+1 <= b:
        ans[sum_a/(i+1)] = ans.get(sum_a/(i+1), 0) + cmb(value[num], kosuu)
print("{:.10f}".format(max(ans)))
print(int(ans[max(ans)]))

Submission status: Accepted

Solution code:
from itertools import accumulate
n, a, b = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort(reverse=True)
acc = list(accumulate(lst))
ansV = 0
ansList = []
for i in range(a, b + 1):
    value = acc[i - 1] / i
    if value > ansV:
        ansV = value
        ansList = [lst[:i]]
    elif value == ansV:
        ansList.append(lst[:i])

def score(l):
    c1 = l.count(l[-1])
    c2 = lst.count(l[-1])
    return comb(c2, c1)

def comb(x, y):
    return fact(x) // fact(x - y) // fact(y)

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

print(ansV)
print(sum(map(score, ansList)))

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


n, a, b = LI()
V = LI()
V.sort()
V.reverse()

cnt = defaultdict(int)
sum_v = 0
for i in range(a):
    sum_v += V[i]
    cnt[V[i]] += 1

# 大きい順にa個選ぶ場合，価値の平均値は最大となる
print(sum_v / a)

# a個選んだ中で一番価値の低いものがいくつ残っているか数える
min_v = V[i]
min_cnt = cnt[min_v]
for i in range(a, n):
    v = V[i]
    if v != min_v:
        break
    cnt[v] += 1

if cnt[min_v] == min_cnt:
    print(1)
    exit()
elif len(cnt.keys()) != 1:
    print(comb(cnt[min_v], min_cnt))
    exit()
ans = 0
for i in range(b - a + 1):
    if cnt[min_v] < min_cnt + i:
        break
    ans += comb(cnt[min_v], min_cnt + i)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            ts = 0
            for c in range(A, min(all_counter[fv], B) + 1):
                ts += factorial(all_counter[fv]) // factorial(c) // factorial(all_counter[fv] - c)
            ans *= ts
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])

if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter

MAX = 51
# 階乗テーブル
factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
    factorial[i] = factorial[i-1] * i

# 組み合わせの数(必要な階乗のテーブルを事前に作っておく)
def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = factorial[r] * factorial[n-r]
    return numerator / denominator

round = lambda x: int((x*2+1) // 2)

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

# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値から欲しいので降順ソートしておく
vN.sort(reverse=True)

mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
    avg = sum(vN[:i]) / i
    if avg == mx_avg:
        # 平均値が最大になるなら、選び方リストに追加
        lists.append(vN[:i])

ans = 0
for l in lists:
    # 選び方を、同じ値の個数毎にまとめる
    c2 = Counter(l)
    combs = 1
    for k, v in c2.items():
        # 同じ値が複数ある場合の組み合わせを出す
        combs *= nCr(c[k], v)
    ans += combs
print(mx_avg)
print(round(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter
from math import factorial

def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    return factorial(n) / factorial(r) / factorial(n-r)

round = lambda x: int((x*2+1) // 2)

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

# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値が欲しいので降順ソートしておく
vN.sort(reverse=True)

mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
    avg = sum(vN[:i]) / i
    if avg == mx_avg:
        # 平均値が最大になるなら、選び方リストに追加
        lists.append(vN[:i])

ans = 0
for l in lists:
    # 選び方を、同じ値の個数毎にまとめる
    c2 = Counter(l)
    combs = 1
    for k, v in c2.items():
        # 同じ値が複数ある場合の組み合わせを出す
        combs *= nCr(c[k], v)
    ans += combs
print(mx_avg)
print(round(ans))

Submission status: Accepted

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

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)

C = [[0]*(N+1) for _ in range(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])


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return C[c[last]][use_last]


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Submission status: Accepted

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

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


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


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Submission status: Accepted

Solution code:
n,a,b,*v=map(int,open(0).read().split())
v=[0]+v
dp=[[[0,1]]+[[0,0]for j in range(b)]for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,b+1):
    if dp[i-1][j-1][0]+v[i]>dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j-1][0]+v[i],dp[i-1][j-1][1]]
    elif dp[i-1][j-1][0]+v[i]==dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]+dp[i-1][j-1][1]]
    else:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]]
m=0
for i in range(a,b+1):
  m=max(m,dp[-1][i][0]/i)
print(m,sum(dp[-1][i][1]*(dp[-1][i][0]/i==m)for i in range(a,b+1)),sep='\n')

Submission status: Accepted

Solution code:
from scipy.misc import comb
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

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

V_Ath = V[A - 1]
V_Ath_CNT = V.count(V_Ath)
V_than_Ath_CNT = len([v for v in V if v > V_Ath])

if max(V) == V_Ath:
    for n in range(A, B + 1):
        ans2 += comb(V_Ath_CNT, n, 1)
else:
    ans2 = comb(V_Ath_CNT, A - V_than_Ath_CNT, 1)

print(ans1)
print(ans2)

Submission status: Accepted

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

V.sort(reverse=True)

sumV = 0
for i in range(A):
    sumV += V[i]
ans1 = sumV/A

# 
cntV0 = 0
for i in range(N):
    if V[i]==V[0]:
        cntV0 += 1
ans2 = 1
if cntV0 > A:
    ans2 = 0
    for i in range(A,min(cntV0,B)+1):
        tmp = 1
        c = cntV0
        r = i
        for j in range(r):
            tmp *= c-j
            tmp //= j+1
        ans2 += tmp
else:
    cntV1,cntV2 = 0,0
    for i in range(N):
        if V[i]==V[A-1]:
            cntV1 += 1
        elif V[i]>V[A-1]:
            cntV2 += 1
    if cntV1+cntV2 > A:
        c = cntV1
        r = A-cntV2
        for i in range(r):
            ans2 *= c-i
            ans2 //= i+1


print(ans1, ans2)

Submission status: Accepted

Solution code:
def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


N, A, B = map(int, input().split())
v_list = list(map(int, input().split()))
v_list.sort(reverse=True)

mean_max = sum(v_list[:A]) / A
comb = 0
if v_list[0] != v_list[A-1]:
    x = v_list.count(v_list[A-1])
    y = v_list[:A].count(v_list[A-1])
    comb = combination(x, y)
else:
    x = v_list.count(v_list[A-1])
    for i in range(A, B+1):
        if v_list[i-1] == v_list[0]:
            comb += combination(x, i)

print("{:.10f}".format(mean_max))
print(comb)

Submission status: Accepted

Solution code:
def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


N, A, B = map(int, input().split())
v_list = list(map(int, input().split()))
v_list.sort(reverse=True)

mean_max = sum(v_list[:A]) / A
comb = 0
if v_list[0] != v_list[A-1]:
    x = v_list.count(v_list[A-1])
    y = v_list[:A].count(v_list[A-1])
    comb = combination(x, y)
else:
    x = v_list.count(v_list[A-1])
    for i in range(A, B+1):
        if v_list[i-1] == v_list[0]:
            comb += combination(x, i)

print(mean_max)
print(comb if comb != 0 else 1)

Submission status: Accepted

Solution code:
def combination(n, r):  # nCrを求める
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
ans1 = sum(v[:a])/a
num1 = v[:a].count(v[a-1])
num2 = v[a:n].count(v[a-1])

ans2 = 0
if v[0] == v[a]:
    for i in range(a,n):
        if v[i] == v[a-1]:
            idx = i + 1
    for i in range(a,min(b,idx) + 1):
        ans2 += combination(num1 + num2, i)
else:
    ans2 = combination(num1 + num2,num1)

print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
N, A, B = [int(_) for _ in input().split()]
V = sorted([int(_) for _ in input().split()], reverse=True)
mp = {}
for v in V:
    mp[v] = mp.get(v, 0) + 1


def fact(x):
    ans = 1
    for i in range(1, x + 1):
        ans *= i
    return ans


def comb(n, r):
    return fact(n) // fact(r) // fact(n - r)


keys = sorted(mp.keys(), reverse=True)
if mp[keys[0]] >= A:
    print(keys[0])
    print(
        sum([comb(mp[keys[0]], i) for i in range(A, 1 + min(mp[keys[0]], B))]))
else:
    count = 0
    for k in keys:
        count += mp[k]
        if count >= A:
            print(sum(V[:A]) / A)
            print(comb(mp[k], A - count + mp[k]))
            break

Submission status: Accepted

Solution code:
import math
n, a, b = list(map(int, input().split()))
v = list(map(int, input().split()))
v.sort(reverse = True)
ans = 0
many = 0
for i in range(a, b + 1) :
	vsumany = sum(v[:i])
	ansi = vsumany / (i)
	if ans <= ansi :
		ans = ansi
		ci = v.count(v[i - 1])
		cin = v[:i].count(v[i - 1])
		m = math.factorial(ci)//math.factorial(cin)//math.factorial(ci-cin)
		many += m
print(ans)
print(many)

Submission status: Accepted

Solution code:
from scipy.misc import comb
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

# 価値の平均の最大値を出力
print(sum(V[:A]) / A)

# A番目に大きいものがいくつあるか
C = V.count(V[A - 1])
if max(V) != V[A - 1]:
    # あと何個選ぶ必要があるか
    remain = A - len([v for v in V if v > V[A - 1]])
    print(comb(C, remain, 1))
else:
    ans = 0
    for i in range(A, B + 1):
        ans += comb(C, i, 1)
    print(ans)

Submission status: Accepted

Solution code:
import math


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


N, A, B = map(int, input().split())
V = list(sorted(map(int, input().split()), key=lambda x: -x))

s = [0]

for i in range(N):
    s.append(s[-1] + V[i])

max_mean = 0
for i in range(A, B + 1):
    m = s[i] / i
    if max_mean < m:
        max_mean = m

ret = 0

for i in range(A, B + 1):
    m = s[i] / i
    if m == max_mean:
        k = 0
        for p in range(i):
            if V[p] == V[i - 1]:
                k += 1
        ret += combination(V.count(V[i - 1]), k)
print(max_mean)
print(ret)

Submission status: Accepted

Solution code:
from math import factorial

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

maxave = 0

for i in range(A, B+1):
    if sum(v[:i]) / i < maxave:
        continue
    
    counter1 = 1
    for j in range(i-2, -1, -1):
        if v[j] == v[i-1]:
            counter1 += 1
        else:
            break

    counter2 = v.count(v[i-1])

    now_counter = factorial(counter2) // factorial(counter2 - counter1) // factorial(counter1)

    if sum(v[:i]) / i == maxave:
        nummax += now_counter
    else:
        nummax = now_counter
        maxave = sum(v[:i]) / i
    
print(maxave)
print(nummax)

Submission status: Accepted

Solution code:
N, A, B = (int(i) for i in input().split())
V = [int(i) for i in input().split()]
V.sort()
V = V[::-1]

key = V[A-1]
cca = 0
ccb = 0
kk = 0

def combination(a, b):
    res = 1
    for i in range(a, a - b, -1):
        res = res * i
    for i in range(b):
        res = res // (i + 1)
    return res

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

for i in range(A):
    if V[i] == key:
        cca += 1
for i in range(N):
    if V[i] == key:
        ccb += 1

if cca == A:
    res = 0
    for i in range(A, B+1):
        res += combination(ccb, i)
else:
    res = combination(ccb, cca)
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import factorial as fact
def comb(n,r):
    return fact(n) // (fact(r)*fact(n-r))

n,a,b = map(int, input().split())
vl = list(map(int, input().split()))
vl.sort(reverse=True)

res_avg = sum(vl[:a])/a
res_cnt = 0
last_v = vl[a-1]

cnt_all = 0
for v in vl:
    if v==last_v:
        cnt_all += 1

for m in range(a,b+1):
    if sum(vl[:m])/m == res_avg:
        cnt_in = 0
        for i in range(m):
            if last_v==vl[i]:
                cnt_in += 1
        res_cnt += comb(cnt_all, cnt_in)

print("{:6f}".format(res_avg))
print(res_cnt)

Submission status: Accepted

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

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

v.sort(reverse=True)
ans1 = sum(v[0:A]) / A

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i + 1
    for i in range(A, min(B, idx) + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
import numpy as np

def nCr(n, r):
    c = 1
    for i in range(n - r + 1, n + 1):
        c *= i
    for i in range(1, r + 1):
        c //= i
    return c

if __name__ == '__main__':
    
    N, A, B = map(int, input().split())
    v0 = list(map(int, input().split()))    
    v = np.array(v0, dtype = np.int64)
    v = np.sort(v)[::-1]
    
    ave = 0
    comb = 0
    
    if v[A - 1] == v[0]:
        ave = v[0]
        n = np.sum(v == v[0])
        for i in range(A, min(B, n) + 1):
            comb += nCr(n, i)
    else:
        n0 = np.sum(v > v[A - 1])
        n1 = np.sum(v == v[A - 1])
        comb = nCr(n1, A - n0)
        ave = np.sum(v[0: A]) / A
        
    print(ave)
    print(comb)

Submission status: Accepted

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

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

mx = sum(v[:A])
ans1 = mx/A
a = v[A - 1]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)

Submission status: Accepted

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

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

mx = sum(v[:A])
ans1 = mx/A
a = v[A]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
import math
n, a, b = map(int, input().split())
v = [int(m) for m in input().split()]
v.sort(reverse=True)

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


k = 0
l = 0
maxli = []
for i in range(a, b + 1):
    w = v[:i]
    avgv = sum(w) / i
    x = v[i - 1]
    for u in range(len(w) - 1, -1, -1):
        if u == len(w) - 1:
            l = 1
        else:
            if v[u] == v[u + 1]:
                l += 1
            else:
                break
    for j in range(i - 1, n):
        if j == i - 1:
            k = 1
        else:
            if v[j] == v[j - 1]:
                k += 1
            else:
                break
    k -= 1
    maxli.append([avgv, comb(l + k, l)])

S = 0
K = 0
maxli.sort(reverse=True)
for i in range(len(maxli)):
    if i == 0:
        S = maxli[i][0]
        K = maxli[i][1]
    else:
        if maxli[i][0] == maxli[i - 1][0]:
            K += maxli[i][1]
        else:
            break
print(S)
print(K)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
goods=[int(i) for i in input().split()]
dp=[[[0,0] for i in range(N+1)] for i in range(N)]
for i in range(N):
  for j in range(i+2):
    if i==0 and j==1:
      dp[0][1]=[goods[i],1]
    elif j==0:
      dp[i][0]=[0,1]
    else:
      if dp[i-1][j][0]<dp[i-1][j-1][0]+goods[i]:
        dp[i][j][0]=dp[i-1][j-1][0]+goods[i]
        dp[i][j][1]=dp[i-1][j-1][1]
      elif dp[i-1][j][0]>dp[i-1][j-1][0]+goods[i]:
        dp[i][j][0]=dp[i-1][j][0]
        dp[i][j][1]=dp[i-1][j][1]
      else:
        dp[i][j][0]=dp[i-1][j-1][0]+goods[i]
        dp[i][j][1]=dp[i-1][j-1][1]+dp[i-1][j][1]
                           
ans1,ans2=0,0
for i in range(A,B+1):
  if ans1<dp[N-1][i][0]/i:
    ans1=dp[N-1][i][0]/i
    ans2=dp[N-1][i][1]
  elif ans1==dp[N-1][i][0]/i:
    ans2+=dp[N-1][i][1]
print(ans1)
print(ans2)