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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, V):
    V.sort(reverse=True)
    mean = sum(V[:A])/N

    print(mean)

    if A == N:
        return 1

    c = 0
    for i in range(A, N):
        if V[i] == V[i-1]:
            c += 1
        else:
            break

    if c == 0:
        return 1

    d = 1
    for i in range(A-1, -1, -1):
        if i > 1 and V[i] == V[i-1]:
            d += 1
        else:
            break

    @lru_cache(maxsize=None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n-1, r-1)+comb2(n-1, r)
    return sum([comb2(c+d, i) for i in range(1, c+1)])


def main():
    N, A, B = read_int_n()
    V = read_int_n()

    print(slv(N, A, B, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, V):
    V.sort(reverse=True)
    mean = sum(V[:A])/N

    print(mean)

    if A == N:
        return 1

    c = 0
    for i in range(A, N):
        if V[i] == V[i-1]:
            c += 1
        else:
            break

    if c == 0:
        return 1

    d = 1
    for i in range(A-1, -1, -1):
        if i > 1 and V[i] == V[i-1]:
            d += 1
        else:
            break

    @lru_cache(maxsize=None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n-1, r-1)+comb2(n-1, r)
    print(c, d)
    return sum([comb2(c+d, i) for i in range(1, c+1)])


def main():
    N, A, B = read_int_n()
    V = read_int_n()

    print(slv(N, A, B, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

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

# 二項係数の準備
MOD = 9007199254740997
inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

V.sort(reverse=True)

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

ans = 0
if V[0] == V[A-1]:
    v = V.count(V[A-1])
    u = min(v,B)
    for i in range(A,u+1):
        ans += nCr(v,i,MOD,fac,facInv)

else:
    v_all = V.count(V[A-1])
    v_ch = V[:A].count(V[A-1])
    print(v_all,v_ch)
    ans = nCr(v_all,v_ch,MOD,fac,facInv)

print(ans)

Submission status: Wrong Answer

Solution code:
# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

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

# 二項係数の準備
MOD = 9007199254740997

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

V.sort(reverse=True)

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

ans = 0
if V[0] == V[A-1]:
    v = V.count(V[A-1])
    u = min(v,B)
    for i in range(A,u+1):
        ans += nCr(u,i,MOD,fac,facInv)

else:
    v_all = V.count(V[A-1])
    v_ch = V[:A].count(V[A-1])
    ans = nCr(v_all,v_ch,MOD,fac,facInv)

print(ans)

Submission status: Wrong Answer

Solution code:
# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

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

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

V.sort(reverse=True)

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

ans = 0
if V[0] == V[A-1]:
    v = V.count(V[A-1])
    u = min(v,B)
    for i in range(A,u+1):
        ans += nCr(u,i,MOD,fac,facInv)

else:
    v_all = V.count(V[A-1])
    v_ch = V[:A].count(V[A-1])
    ans = nCr(v_all,v_ch,MOD,fac,facInv)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod


#0.入力
N,A,B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)
#1.m = [0,A)の中で最も小さい数
mxv_avg = sum(V[:A])/A
print(mxv_avg)

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

# Vの要素が単一ならnCa + ... + nCb
# そうでないならnCk
cnt = Counter(V)
ans = 0
if V[0] == V[A-1]:
    tob = V[:B].count(V[A-1])
    for i in range(A,B+1):
        ans += nCr(tob,i,MOD,fac,facInv)
    print(ans)

else:
    cnt_min_choose = V[0:A].count(V[A-1])
    cnt_min_all = V.count(V[A-1])
    ans = nCr(cnt_min_all, cnt_min_choose, MOD,fac,facInv)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod


#0.入力
N,A,B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)
#1.m = [0,A)の中で最も小さい数
mxv_avg = sum(V[:A])/A
print(mxv_avg)

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

# Vの要素が単一ならnCa + ... + nCb
# そうでないならnCk
cnt = Counter(V)
ans = 0
if V[0] == V[A-1]:
    tob = V[:B].count(V[A-1])
    for i in range(A,B):
        ans += nCr(tob,i,MOD,fac,facInv)
    print(ans)

else:
    cnt_min_choose = V[0:A].count(V[A-1])
    cnt_min_all = V.count(V[A-1])
    ans = nCr(cnt_min_all, cnt_min_choose, MOD,fac,facInv)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod


#0.入力
N,A,B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)
#1.m = [0,A)の中で最も小さい数
mxv_avg = sum(V[:A])/A
print(mxv_avg)

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

# Vの要素が単一ならnCa + ... + nCb
# そうでないならnCk
cnt = Counter(V)
ans = 0
if V[0] == V[A-1]:
    tob = V[:B].count(V[A-1])
    for i in range(A,tob+1):
        ans += nCr(tob,i,MOD,fac,facInv)
    print(ans)

else:
    cnt_min_choose = V[0:A].count(V[A-1])
    cnt_min_all = V.count(V[A-1])
    ans = nCr(cnt_min_all, cnt_min_choose, MOD,fac,facInv)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod


#0.入力
N,A,B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)
#1.m = [0,A)の中で最も小さい数
mxv_avg = sum(V[:A])/A
print(mxv_avg)

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

# Vの要素が単一ならnCa + ... + nCb
# そうでないならnCk
cnt = Counter(V)
ans = 0
if len(cnt) == 1:
    for i in range(A,B+1):
        ans += nCr(N,i,MOD,fac,facInv)
    print(ans)

else:
    cnt_min_choose = V[0:A].count(V[A-1])
    cnt_min_all = V.count(V[A-1])
    for i in range(cnt_min_choose,V[:B].count(V[A-1])+1):
        ans += nCr(cnt_min_all, i, MOD,fac,facInv)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod


#0.入力
N,A,B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)
#1.m = [0,A)の中で最も小さい数
mxv_avg = sum(V[:A])/A
print(mxv_avg)

# 二項係数の準備
MOD = 9999999900000001

inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

# Vの要素が単一ならnCa + ... + nCb
# そうでないならnCk
cnt = Counter(V)
ans = 0
if len(cnt) == 1:
    for i in range(A,B+1):
        ans += nCr(N,i,MOD,fac,facInv)
    print(ans)

else:
    cnt_min_choose = V[0:A].count(V[A-1])
    cnt_min_all = V.count(V[A-1])
    ans = nCr(cnt_min_all, cnt_min_choose, MOD,fac,facInv)
    print(ans)

Submission status: Wrong Answer

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

v = list(map(int,input().split()))
v.sort()
v.reverse()
print(sum(v[:a])/a)


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


c = v.count(v[a-1])
d = v[:a].count(v[a-1])
ans = 0

if v[0] != v[a-1]:
    print(c)
else:
    for i in range(d,min(c,b-a+d)+1):
        ans += combination(c,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
N, A, B = map(int, input().split())
v = [int(vi) for vi in input().split()]

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

v = sorted(v, reverse=True)
basket = v[:A]
max_basket = basket[0]
min_basket = basket[-1]
print(sum(basket) / len(basket))

n_not_candidate_in_basket = 0
n_candidate = 0
for i, vi in enumerate(v):
    if i > B:
        break
    if vi == min_basket:
        n_candidate += 1
    if vi != min_basket and i < A:
        n_not_candidate_in_basket += 1

if min_basket != max_basket:
    capacity = min(B - n_not_candidate_in_basket, n_candidate)
    print(combination(n_candidate, capacity))
else:
    count = 0
    for i in range(A, min(B, n_candidate) + 1):
        count += combination(n_candidate, i)
    print(count)

Submission status: Wrong Answer

Solution code:
N,A,B=[int(x) for x in str(input()).split()]
C=[int(s) for s in str(input()).split()]
v=C
v.sort()
ma=[]
mi=[]
for i in range(B):
  ma.append(v[-1])
  v=v[:len(v)-1]

ma.sort()
ava=0
for i in ma:
  ava+=i

ava/=len(ma)


count=B
while count>A and ma[0]<ava:

  ava=(len(ma)*ava-ma[0])/(len(ma)-1)
  ma=ma[1:]
  count-=1


C1=0
for i in C:
  if i==ma[0]:
    C1+=1
ma1=0
for i in ma:
  if i==ma[0]:
    ma1+=1


factorial=[1]
p=1
for i in range(1,51):
  p*=i
  factorial.append(p)  

print(ava)


print(factorial[C1]//factorial[C1-ma1]//factorial[ma1])

Submission status: Wrong Answer

Solution code:
N,A,B=[int(x) for x in str(input()).split()]
C=[int(s) for s in str(input()).split()]
v=C
v.sort()
ma=[]
mi=[]
for i in range(B):
  ma.append(v[-1])
  v=v[:len(v)-1]

ma.sort()
ava=0
for i in ma:
  ava+=i

ava/=len(ma)


count=B
while count>A and ma[0]<ava:

  ava=(len(ma)*ava-ma[0])/(len(ma)-1)
  ma=ma[1:]
  count-=1


Ans=0
for i in C:
  if i==ma[0]:
    Ans+=1

print(ava)
print(Ans)

Submission status: Wrong Answer

Solution code:
poo=input().split()
shoop=[1]
smop=input().split()
lop=[]
for i in range(int(poo[0])):
    lop.append(int(smop[i]))
    shoop.append(shoop[i]*(i+1))
jop=lop.copy()
j=int(poo[1])
staph=int(poo[2])
joop=0
z=0
zop=jop.count(max(jop))
while z<j:
    joop+=max(lop)
    lop.remove(max(lop))
    z+=1
print(joop/j)
jum=1
shazam=0
while j>=zop:
    shazam+=zop
    j=j-zop
    for i in range(zop):
        jop.remove(max(jop))
    zop=jop.count(max(jop))
if zop>j and j>0:
    jum=0
    som=int(poo[1])
    while min(staph,shazam+zop)>=som:
        while j<=som:
            jum+=shoop[zop]//(shoop[j]*shoop[zop-j])
            j+=1
        som+=1
print(jum)

Submission status: Wrong Answer

Solution code:
def combination(n, r):
    com = [[0 for j in range(r+1)] for i in range(n+1)]
    for i in range(n+1):
        com[i][0] = 1

    for i in range(1, n+1):
        for j in range(1, r+1):
            com[i][j] = com[i-1][j] + com[i-1][j-1]

    return com[n][r]


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

    v.sort(reverse=True)

    num, s, i = [], [], 0
    while i < n:
        cnt = 1
        while i < n-1 and v[i] == v[i+1]:
            cnt += 1
            i += 1
        num.append(cnt)
        s.append(v[i])
        i += 1

    if num[0] >= b:
        com = 0
        for i in range(a, b+1):
            com += combination(num[0], i)
        print(v[0])
    else:
        c, idx = 0, 0
        while c < a:
            c += num[idx]
            idx += 1

        w, m = 0, 0
        for i in range(idx-1):
            w += v[i] * num[i]
            m += num[i]
        w += v[idx-1] * (a-m)

        print(w/a)

        com = combination(num[idx-1], c-num[idx-1])

    print(com)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(1,y+1):
        up*=i
    for i in range(1,x):
        down*=i
    for i  in range(1, y-x+1):
        down*=i
    print(up//down)
else:
    ii=a
    while ii<=b and v[-ii]==v[-1]:
        up=1
        down=1
        for i in range(1,y+1):
            up*=i
        for i in range(1,ii+1):
            down*=i
        for i  in range(1, y-ii+1):
            down*=i
        ans+=(up//down)
        ii+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(2,y+1):
        up*=i
    for i in range(2,x):
        down*=i
    for i  in range(2, y-x+1):
        down*=i
    print(up//down)
else:
    i=a
    while v[-i]==v[-1]:
        for i in range(2,y+1):
            up*=i
        for i in range(2,i+1):
            down*=i
        for i  in range(2, y-i+1):
            down*=i
        ans+=(up//down)
        i-=1
    print(ans)

Submission status: Wrong Answer

Solution code:
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
x=0
am=0
ways=1
tmp=0
y=1
ar=0
while x<a:
    ar+=v[-(x+1)]
    if tmp==v[-(x+1)]:
        y+=1
        del v[-(x+1)]
        tmpcount=v.count(tmp)/y
    else:
        tmp=v[-(x+1)]
        tmpcount=v.count(tmp)
    ways=ways*tmpcount
    x+=1
am=ar/a
print(am)
print(ways)

Submission status: Wrong Answer

Solution code:
import math
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
count=0
if v[0]==v[a-1]:
    for i in range(a,min(b,v.count(v[0]))+1):
        count+=f(min(b,v.count(v[0])),i)
    print(sum(v[:a])/a)
    print(count)
else: 
    print(sum(v[:a])/a)
    print(f(v.count(v[a-1]),v[:a].count(v[a-1])) )

Submission status: Wrong Answer

Solution code:
import math
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
count=0
if a==1 or v[0]==v[a-1]:
    for i in range(a,min(b,v.count(v[0]))+1):
        count+=f(min(b,v.count(v[0])),i)
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(f(v.count(v[a-1]),v[:a].count(v[a-1])) )

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=Counter(v)
count=0
if a==1 or v[0]==v[a-1]:
    for i in range(a,min(b,c[v[0]])+1):
        count+=math.factorial(min(b,c[v[0]])) // (math.factorial(min(b,c[v[0]]) - i) * math.factorial(i))
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(c[v[a-1]])

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=Counter(v)
count=0
if a==1 or v[0]==v[a-1]:
    for i in range(a-1,min(b,c[v[0]])):
        count+=math.factorial(min(b,c[v[0]])) // (math.factorial(min(b,c[v[0]]) - i) * math.factorial(i))
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(c[v[a-1]])

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=Counter(v)
count=1 
if a==1 or v[0]==v[a-1]:
    for i in range(1,min(b,c[v[0]])):
        count+=math.factorial(min(b,c[v[0]])) // (math.factorial(min(b,c[v[0]]) - i) * math.factorial(i))
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(c[v[a-1]])

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())))
ans = sum(v[-a:])/a
print(ans)

same = True
count_in = 1
count_out = 0
x = v[n-a]
for i in range(n-a+1, n):
    if v[i] == x:
        count_in += 1
    else:
        same = False
        break
i = n-a-1
while i >= 0:
    if v[i] == x:
        count_out += 1
    else:
        break
    i -= 1

from scipy.misc import comb

case = 0
count = count_in+count_out
if not same:
    case = comb(count, count_in)
else:
    for i in range(a, b+1):
        case += comb(count, i+count_in-a)
print(int(case))

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())))
ans = sum(v[-a:])/a
print(ans)

same = True
count_in = 1
count_out = 0
x = v[n-a]
for i in range(n-a+1, n):
    if v[i] == x:
        count_in += 1
    else:
        same = False
        break
i = n-a-1
while i >= 0:
    if v[i] == x:
        count_out += 1
    else:
        break
    i -= 1

from scipy.misc import comb

case = 0
count = count_in+count_out
if not same:
    case = comb(count+count, count_in)
else:
    for i in range(a, b+1):
        case += comb(count, i+count_in-a)
print(int(case))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	if n1 == n2:
		print(1)
	else:
		print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	if n1 == 1:
		print(1)
	else:
		for i in range(a, min(n1, b + 1)):
			ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
		print(int(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)
val=0
mi=10**15+1
cnt=0
for i in range(A):
  val+=V[i]
  if V[i]==mi:
    cnt+=1
  else:
    mi=V[i]
    cnt=1

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i)
    
def nCr(n,r):
  return int(factorial[n]/(factorial[r]*factorial[n-r]))    

ave=val/A
if ave == V[0]:
  for i in range(A,N):
    if V[i]==V[0]:
      cnt+=1
    else:
      break
  ans=1
  for i in range(A,min(B+1,cnt+1)):
    ans+=nCr(cnt,i)
  print(ave)
  print(ans)
else:
  res=cnt
  for i in range(A,N):
    if V[i]==V[A-1]:
      res+=1
  print(ave)
  print(nCr(res,cnt))

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)
val=0
mi=10**15+1
cnt=0
for i in range(A):
  val+=V[i]
  if V[i]==mi:
    cnt+=1
  else:
    mi=V[i]
    cnt=1

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i)
    
def nCr(n,r):
  return int(factorial[n]/(factorial[r]*factorial[n-r]))    

ave=val/A
if ave == V[0]:
  for i in range(A,N):
    if V[i]==V[0]:
      cnt+=1
    else:
      break
  ans=1
  for i in range(A,min(B+1,cnt)):
    ans+=nCr(cnt,i)
  print(ave)
  print(ans)
else:
  res=cnt
  for i in range(A,N):
    if V[i]==V[A-1]:
      res+=1
  print(ave)
  print(nCr(res,cnt))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
def ncm(n,m):
    return math.factorial(n)/(math.factorial(m) * math.factorial(n-m))

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = np.array(v)
##print(v)
ansarray = v[0:A]
##print(ansarray)
ave = np.mean(ansarray)
print(float(ave))
mi = min(ansarray)
ma = max(ansarray)
biggerarray = v[v>mi]
m = len(biggerarray)
numminarray = v[v==mi]
a = len(numminarray)
##print(nummin)
##print(num_kouho)
ans = 0
if ma == mi:
    if m+a <= B:
        for i in range(A-m,a+1):
            ans+=ncm(a,i)
    else:
        for i in range(A-m,B-m+1):
            ans+=ncm(a,i)

else:
    ans = a
#print('a=',a)
#print('m=',m)
print(int(ans))

Submission status: Wrong Answer

Solution code:
def comb(left, right):
    top = 1
    for i in range(left, left - right, -1):
        top *= i

    bottom = 1
    for i in range(1, right + 1):
        bottom *= i

    return top // bottom

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

v.sort()

min_set = v[-a:]
print(sum(min_set) / len(min_set))
if len(set(min_set)) == 1:
    cnt = v.count(min_set[0])

    result = 0
    for i in range(1, cnt + 1):
        result += comb(cnt, i)
    print(result)
else:
    print(comb(v.count(min_set[0]), min_set.count(min_set[0])))

Submission status: Wrong Answer

Solution code:
import heapq
import copy
from collections import Counter

N,A,B=map(int, raw_input().split())
v=map(int, raw_input().split())
V=map(lambda n:n*(-1), v) 

def C(n,r):
	bunshi=1
	bunbo=1
	for i in range(n,n-r,-1):
		bunshi*=i
	for i in range(1,r+1):
		bunbo*=i
	return bunshi/bunbo

def Value(u,k):
	cnt=0
	u=copy.deepcopy(V)
	c=Counter(u)
	l=list( c.items() )
	heapq.heapify(l)
	pattern=1

	a=[]
	while cnt<k:
		tmp=heapq.heappop(l)
		if cnt+tmp[1]>k:
			a.append( (tmp[0]*(-1),k-cnt) )
			pattern=C(tmp[1],k-cnt)
			cnt=k
			break
		cnt+=tmp[1]
		a.append( (tmp[0]*(-1),tmp[1]) )

	t_sum=0
	for i,j in a:
		t_sum+=i*j
	return float(t_sum)/float(cnt),pattern


from collections import defaultdict
d = defaultdict(lambda: 0)
for i in range(A,B+1):
	tmp=Value(V,i)
	d[tmp[0]]+=tmp[1]


print sorted(d.items(), key=lambda x: x[0],reverse=True)[0][0]
print sorted(d.items(), key=lambda x: x[0],reverse=True)[0][1]

Submission status: Wrong Answer

Solution code:
def comb(left, right):
    top = 1
    for i in range(left, left - right, -1):
        top *= i

    bottom = 1
    for i in range(1, right + 1):
        bottom *= i

    return top // bottom

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

v.sort()

min_set = v[-a:]
print(sum(min_set) / len(min_set))
if len(set(min_set)) == 1:
    cnt = v.count(min_set[0])

    result = 0
    for i in range(1, cnt + 1):
        result += comb(cnt, i)
    print(result)
else:
    print(v.count(min_set[0]))

Submission status: Wrong Answer

Solution code:
def comb(left, right):
    top = 1
    for i in range(left, left - right, -1):
        top *= i

    bottom = 1
    for i in range(1, right + 1):
        bottom *= i

    return top // bottom

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

v.sort()

min_set = v[-a:]
print(sum(min_set) / len(min_set))
if len(set(min_set)) == 1:
    cnt = v.count(min_set[0])
else:
    cnt = a

result = 0
for i in range(1, cnt + 1):
    result += comb(cnt, i)
print(result)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import math
import copy

def nClr(n,l,r):
	ans = 0
	pat = 1
	if l == 0:
		ans += 1
		l += 1

	for i in range(l-1):
		pat *= ((n-i)/(i+1))

	for i in range(l-1,r):
		pat *= ((n-i)/(i+1))
		ans +=  pat

	return int(ans)

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

v.sort(reverse=True)

mean =float(sum(v[0:A]))/float(A)
whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


if len(ran_A) == 1:
	n = min(B,whole[v[0]])
	num = nClr(whole[v[0]],A,n)
	print(mean)
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])


print(mean)
print(math.ceil(num))