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: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, A, B = getNM()
V = sorted(getList(), reverse = True)

print(sum(V[:A]) / A)

dict = defaultdict(int)
for i in range(N):
    dict[V[i]] += 1

r = A
n = 0
for i in dict.items():
    if r - i[1] >= 0:
        r -= i[1]
    else:
        n = i[1]
        break

def cmb_1(n, r):
    r = min(n - r, r)
    # 今回は0個の中からr個選ぶ時1が返されるようにする
    if n == 0:
        return 1
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

ans = 0
if r > 0 and V[0] == V[A - 1]:
    for i in range(r, B + 1):
        ans += cmb_1(n, i)
else:
    ans += cmb_1(n, r)

print(ans)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, A, B = getNM()
V = sorted(getList(), reverse = True)

print(sum(V[:A]) / A)

dict = defaultdict(int)
for i in range(N):
    dict[V[i]] += 1

r = A
n = 0
for i in dict.items():
    if r - i[1] >= 0:
        r -= i[1]
    else:
        n = i[1]
        break

def cmb_1(n, r):
    r = min(n - r, r)
    # 今回は0個の中からr個選ぶ時1が返されるようにする
    if n == 0:
        return 1
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

ans = 0
if r > 0 and V[0] == V[A - 1]:
    # n個から r ~ r + (B - A)個選ぶ通り
    for i in range(r, r + (B - A) + 1):
        ans += cmb_1(n, i)
else:
    ans += cmb_1(n, r)

print(ans)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, A, B = getNM()
V = sorted(getList(), reverse = True)

print(sum(V[:A]) / A)

dict = defaultdict(int)
for i in range(N):
    dict[V[i]] += 1

r = A
n = 0
for i in dict.items():
    if r - i[1] >= 0:
        r -= i[1]
    else:
        n = i[1]
        break

def cmb_1(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

ans = 0
if r > 0 and V[0] == V[A - 1]:
    # n個から r ~ r + (B - A)個選ぶ通り
    for i in range(r, r + (B - A) + 1):
        ans += cmb_1(n, i)
else:
    ans += cmb_1(n, r)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
Vs = list(mapint())
Vs.sort(reverse=True)
from collections import defaultdict, Counter
from scipy.special import comb

count = defaultdict(int)
c = Counter(Vs)
ans = 0
for i in range(A, B+1):
    val = sum(Vs[:i])/i
    if val>=ans:
        ans = val
        lowest_cnt = 0
        lowest = Vs[i-1]
        for j in range(i):
            if Vs[j]==lowest:
                lowest_cnt += 1
        count[int(ans*2)] += comb(c[lowest], lowest_cnt)

print(ans)
print(count[int(ans*2)])

Submission status: Runtime Error

Solution code:
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
a=v[:A]
b=v[:B]
avg=sum(a)/A
print(avg)
c=[[0]*51 for _ in range(51)]
c[0][0]=1
for i in range(50):
  c[i+1][0]=1
  c[i+1][i+1]=1
  for j in range(i):
    c[i+1][j+1]=c[i][j]+c[i][j+1]
if a[0]==a[-1]:
  ans=0
  x=v.count(a[0])
  for i in range(A,B+1):
    if i<=x:
      ans+=C[x][i]
else:
  x=v.count(a[-1])
  y=a.count(a[-1])
  ans=c[x][y]
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    double v[n];
    map<double, int, greater<double>> mp;
    rep (i, 0, n) {
        cin >> v[i];
        mp[v[i]]++;
    }
    int cnt = 0;
    double sum = 0;
    ll ans = 1;
    double ave = 0;
    for (auto p : mp) {
        if (cnt + p.second < a) {
            sum += p.second * p.first;
            cnt += p.second;
        } else if (a <= cnt + p.second) {
            if (cnt == 0) {
                ans=0;
                rep(k,A,min(B,p.second)+1){
                    ll tmp=1;
                    rep (i, 1, p.second + 1) tmp *= i;
                    rep (i, 1, k + 1) tmp /= i;
                    rep (i, 1, p.second - k + 1) tmp /= i;
                    ans+=tmp;
                }
                ave = p.first;

            } else {
                int cnt2 = a - cnt;
                rep (i, 1, p.second + 1) ans *= i;
                rep (i, 1, cnt2 + 1) ans /= i;
                rep (i, 1, p.second - cnt2 + 1) ans /= i;
                ave = (sum + cnt2 * p.first) / a;
            }
            break;
        }
    }
    cout << fixed << setprecision (15) << ave << "\n" << ans << "\n";
}

Submission status: Runtime Error

Solution code:
from collections import Counter
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_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()

assert 1==2

tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val
        assert tmp_num<A

assert 1==2

Submission status: Runtime Error

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

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

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        assert val!=rest
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Runtime Error

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

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

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert 1==2
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
from scipy.special import comb
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Submission status: Runtime Error

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    assert 1==2
    print(tmp_sum/tmp_num)
    print(1)
else:
    assert 1==2
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Runtime Error

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    assert 1==2
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Submission status: Runtime Error

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

V_C=Counter(V)

tmp_sum=0
tmp_num=0


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[val]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
    if tmp_num>=A:
        break
else:
    #A個になるまで追加する
    exit()

print(tmp_sum/tmp_num)
print(1)

Submission status: Runtime Error

Solution code:
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
d = collections.Counter(A)
A.sort(reverse=1)
ans = []
for i in range(a, b):
    ans.append([sum(A[:i]) / i, i])
maxx = max(ans, key=lambda i: i[0])
comd = 1
for i in range(maxx[1]):
    comd *= d[A[i]]
print(maxx[0])
print(comd)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    from collections import Counter
    from scipy.mist import comb

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    from collections import Counter
    from mist.special import comb

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    from collections import Counter
    from scipy.special import comb

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

    V.sort(reverse = True)
    max_list = V[0:A]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max < a:
            max_list = V[0:i]
            max = a
    print("{:.6f}".format(max))

    ans = 1
    max_list = Counter(max_list).most_common()
    for i in range(len(max_list)):
        ans *= comb(V.count(max_list[i][0]),max_list[i][1])
    print(int(ans))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v = sorted(v)
maxv = sum(v[N-A:])/A
ans1 = maxv
minyouso = v[N-A]
maxyouso = v[N-1]
if minyouso != maxyouso:
    total = v.count(minyouso)
    saitei = v[N-A:].count(minyouso)
    ans2 = cmb(total, saitei)
else:
    total = v.count(minyouso)
    saitei = v[N-A:].count(minyouso)
    zouka = B-A
    ans2 = 0
    for i in range(zouka+1):
        ans2 += cmb(total, saitei+i)
print("{:.05f}".format(ans1))
print(ans2)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

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

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v = sorted(v)
maxv = sum(v[N-A:])/A
ans1 = maxv
minyouso = v[N-A]
maxyouso = v[N-1]
if minyouso != maxyouso:
    total = v.count(minyouso)
    saitei = v[N-A:].count(minyouso)
    ans2 = cmb(total, saitei)
else:
    total = v.count(minyouso)
    saitei = v[N-A:].count(minyouso)
    zouka = B-A
    ans2 = 0
    for i in range(zouka+1):
        ans2 += cmb(total, saitei+i)
print(ans1)
print(ans2)

Submission status: Runtime Error

Solution code:
comb_memo = {}
def comb(n, r):
  global comb_memo
  if (n, r) in comb_memo:
    return comb_memo[(n, r)]
  else:
    r = min(r, n-r)
    res = 1
    for _ in range(r):
      res *= n
      n -= 1
    for i in range(1, r+1):
      res //= i
    comb_memo[(n, r)] = res
    comb_memo[(n, n-r)] = res
    return res

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

mu = sum(v[:A]) / A
if v[0] == mu:
  R = v.count(v[0])

ans = 0
if R > A:
  for i in range(A, B+1):
    if i > R:
      break
    ans += comb(R, i)
else:
  min_v = v[A-1]
  n = v.count(min_v)
  need = v[:A].count(min_v)
  ans += comb(n, need)

print(mu)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

f_memo = {0:1, 1:1}
def f(x):
  global f_memo
  if x in f_memo:
    return f_memo[x]
  else:
    res = x * f(x-1)
    f_memo[x] = res
    return res

comb_memo = {}
def comb(n, r):
  global comb_memo
  if (n, r) in comb_memo:
    return comb_memo[(n, r)]
  else:
    a = f(n)
    b = f(n-r)
    c = f(r)
    res = a // b // c
    comb_memo[(n, r)] = res
    return res


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

mu = sum(v[:A]) / A
R = A-1
for i in range(A, N):
  if v[i] == mu:
    R = i
  else:
    break

R += 1
ans = 0
if R > A:
  for i in range(A, B+1):
    ans += comb(R, i)
else:
  min_v = v[A-1]
  n = v.count(min_v)
  need = v[:A].count(min_v)
  ans += comb(n, need)

print(mu)
print(ans)

Submission status: Runtime Error

Solution code:
f_memo = {0:1, 1:1}
def f(x):
  global f_memo
  if x in f_memo:
    return f_memo[x]
  else:
    res = x * f(x-1)
    f_memo[x] = res
    return res

comb_memo = {}
def comb(n, r):
  global comb_memo
  if (n, r) in comb_memo:
    return comb_memo[(n, r)]
  else:
    a = f(n)
    b = f(n-r)
    c = f(r)
    res = a // b // c
    comb_memo[(n, r)] = res
    return res


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

mu = sum(v[:A]) / A
R = A-1
for i in range(A, N):
  if v[i] == mu:
    R = i
  else:
    break

R += 1
ans = 0
if R > A:
  for i in range(A, B+1):
    ans += comb(R, i)
else:
  min_v = v[A-1]
  n = v.count(min_v)
  need = v[:A].count(min_v)
  ans += comb(n, need)

print(mu)
print(ans)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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

if len(set(v)) == 1:
    print(xx)

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


n = v[:A].count(min(v[:A]))
m = v.count(min(v[:A]))
print(cmb(m,n))

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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

if len(set(v)) == 1:
    print(xx)

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


n = v[:A].count(min(v[:A]))
m = v.count(min(v[:A]))
print(n,m)
print(cmb(m,n))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

N,A,B = map(int,input().split())
V = sorted(list(map(int,input().split())),reverse = True)

a = A - 1
top = V[0]
ans = 0

if top == V[a]:
  d = 1
  for i in range(a,N):
    if V[i] != top:
      b = i
      break
  if A == B:
    n = reduce(mul,[t for t in range(A,b + 1)])
    d = reduce(mul,[k for k in range(1,A + 1)])
    ans = n / d
  else:
    for i in range(1,b + 1):
      n = 1
      d *= i
      if i < A:
        continue
      for j in range(b,b - i,-1):
        n *= j
        print(n,d)
      n /= d
      ans += n
  print(float(top))
  print(int(ans))
else:
  sect = V[:A]
  ave = sum(sect) / A
  print(ave)
  con = V.count(V[a])
  ind = V.index(V[a])
  i = a - ind + 1
  if a == ind:
    print(con)
  else:
    n = reduce(mul,[t for t in range(con - i + 1,con + 1)]) 
    d = reduce(mul,[k for k in range(1,i + 1)])
    print(int(n/d))

Submission status: Runtime Error

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

N,A,B = map(int,input().split())
V = sorted(list(map(int,input().split())),reverse = True)
a = A - 1
top = V[0]
ans = 0

if top == V[a]:
  d = 1
  for i in range(1,B + 1):
    if V[i] != top:
      B = i
      break
  for i in range(1,B + 1):
    n = 1
    d *= i
    
    if i < A:
      continue
    for j in range(B,B - i,-1):
      n *= j
    n /= d
    ans += n
  print(float(top))
  print(int(ans))
else:
  sect = V[:A]
  ave = sum(sect) / A
  print(ave)
  con = V.count(V[a])
  ind = V.index(V[a])
  i = a - ind + 1
  if a == ind:
    print(con)
  else:
    n = reduce(mul,[t for t in range(con - i + 1,con + 1)]) 
    d = reduce(mul,[k for k in range(1,i + 1)])
    print(int(n/d))

Submission status: Runtime Error

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

N,A,B = map(int,input().split())
V = sorted(list(map(int,input().split())),reverse = True)

ans = 0

if len(set(V)) == 1:
  d = reduce(mul,[i for i in range(1,A)])
  for i in range(A,B + 1):
    n = 1
    d *= i
    for j in range(B,B - i,-1):
      n *= j
    n /= d
    ans += n
  print(float(V[0]))
  print(int(ans))
else:
  a = A - 1
  sect = V[:A]
  ave = sum(sect) / A
  print(ave)
  con = V.count(V[a])
  ind = V.index(V[a])
  i = a - ind + 1
  if a == ind:
    print(con)
  else:
    n = reduce(mul,[t for t in range(con - i + 1,con + 1)]) 
    d = reduce(mul,[k for k in range(1,i + 1)])
    print(int(n/d))

Submission status: Runtime Error

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

N,A,B = map(int,input().split())
V = sorted(list(map(int,input().split())),reverse = True)

total = 0
pattern = 0

if len(set(V)) == 1:
  for i in range(1,B):
    c = 1
    for j in range(B,B - i,-1):
      c *= j
    d = [t for t in range(1,i + 1)]
    d = reduce(mul,d)
    c /= d
    pattern += c
  a = A - 1
  print(float(V[0]))
  print(int(pattern) + 1)
else:
  a = A - 1
  sect = V[:A]
  total += sum(sect) / A
  print(total)
  con = V.count(V[a])
  ind = V.index(V[a])
  C = con - ind
  if con == ind:
    print(1)
  else:
    numer = reduce(mul,[k for k in range(C,con + 1)]) 
    denom = reduce(mul,[k for k in range(1,C + 1)])
    print(int(numer/denom))

Submission status: Runtime Error

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    count = 0
    d = []
    l = {}
    for i in range(N):
        a,b = map(int, input().split())
        d.append(a)
        l[a] = b
    d.sort()
    
    for i in d:
        count += l[i]
        if count >= K:
            print(i)
            break
        

        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
import math
import numpy as np


def main():
    def perm(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    d = [0] * N
    q = []
    d[:] = map(int, input().split())
    dic={}
    dic_d = {}
    k = 0
    d.sort(reverse=True)
    s = sum(d[:A])
    m = s/A
    for i in set(d):
        dic_d[i] = d.count(i)
            
        
    print("{:.6f}".format(m))
    
    
    for i in set(d):
        
        l = len(q)
        
        if l > 0:
            for j in range(l):
                for h in range(len(dic[q[j]])):
                    if dic[q[j]][h][0] >= B:
                        break
                    s = q[j] * dic[q[j]][h][0] + i
                    ave = s/(dic[q[j]][h][0]+1)
                    
                    if not ave in q:
                        dic[ave] = []
                        q.append(ave)
                        dic[ave].append([dic[q[j]][h][0]+1,dic[q[j]][h][1]])#[j]][g][1]] for g in range(len(dic[q[j]]))]
                    elif ave in q:
                        for g in range(len(dic[q[j]])):
                            ave_j = np.array(dic[ave])
                            if not dic[q[j]][g][0]+1 in ave_j[:,0]:
                                dic[ave].append([dic[q[j]][h][0]+1,dic[q[j]][h][1]])
                            else:
                                for f in range(len(dic[ave])):
                                    if dic[ave][f][0]  == dic[q[j]][g][0]+1:
                                        dic[ave][f][1] += 1
                            
                        
        if not i in q:
            q.append(i)
            dic[i] = []
            for h in range(1, dic_d[i]+1):
                
                dic[i].append([h,int(perm(dic_d[i],h))])
        elif i in q:
            for h in range(1,dic_d[i]+1):
                if dic[i][h][0] <= dic_d[i]:
                    dic[i][h][1] += perm(dic_d[i],dic[i][h][0])
                else:
                    dic[i].append([h, perm(dic_d[i],h)])
                    
    
    ave_np = np.array(dic[m])
    
    for i in range(len(dic[m])):
        if ave_np[i,0] <= B:
            ave_count = sum(ave_np[:i+1,1])
    print(ave_count)
if __name__ == "__main__":
    main()