Problem:


Score : 400 points

Problem Statement

You are given N items.

The value of the i-th item (1 \leq i \leq N) is v_i.

Your have to select at least A and at most B of these items.

Under this condition, find the maximum possible arithmetic mean of the values of selected items.

Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.  

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

The input is given from Standard Input in the following format:

N A B
v_1
v_2
...
v_N

Output

Print two lines.

The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.

The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.

There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

There can be multiple ways to select items so that the mean of the values will be maximized.

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1



Sample input:
5 2 2
1 2 3 4 5


Sample output:
4.500000
1

Submission status: Wrong Answer

Solution code:
import math

N,A,B = map(int, input().strip().split(' '))
V = sorted(list(map(int, input().strip().split(' '))))
max_sum = sum(V[-A:])
print(max_sum/A)

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

if min(V) == max(V):
  ans = 0
  for r in range(A, B+1):
    ans += Combination(N, r)
  print(int(ans))
else:
  print(int(Combination(V.count(V[-A]), V[-A:].count(V[-A]))))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from operator import mul
from functools import reduce

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

V.sort(reverse=True)




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

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

c = 0
for i in range(A-1, B):
    if V[i] == V[A-1]:
        c += 1
#print(V, V[A-1])

for i, v in enumerate(V):
    if v == V[A-1]:
        ia = i
        break
l = A - ia
maxl = V.count(V[A-1])
#print(A, ia, l, maxl, c)
if ia == 0:
    ans = 0
    for d in range(c):
        ans += cmb(maxl, l+d)
else:
    ans = cmb(maxl, l)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from statistics import mean
from bisect import bisect_left
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

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

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

    return result


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort()
    ave = mean(v[N-A:])
    ma = v[0]
    print(ave)

    C = bisect_left(v, v[A-1])
    D = bisect_left(v, v[A-1]+1)
    if ma == ave:
        # すべて同じ価値の場合
        # A個に拘らなくて良い。
        tot = 0
        for i in range(A, B+1):
            tot += cmb(D-C, i-C)
        print(tot)
    else:
        print(cmb(D-C, A-C))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, v)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from statistics import mean
from bisect import bisect_left
INF = float("inf")


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort()
    print(mean(v[N-A:]))
    print(2**(bisect_left(v, v[A-1]+1) - bisect_left(v, v[A-1]))-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, v)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    n = II()
    ans = inf
    for i in range(1, int(math.sqrt(n)) + 1):
        if not n % i:
            ans = min(ans, max(int(math.log(i, 10)), int(math.log(n // i, 10))))
    print(ans+1)
    return

#D
def D():
    _, a, b = LI()
    v = LI()
    v.sort(reverse=True)
    d = defaultdict(int)
    ans = defaultdict(int)
    for vi in v:
        d[vi] += 1
    for i in range(a, b + 1):
        res = v[:i]
        r = res[-1]
        tmp = res.count(r)
        ans[sum(res) / i] += int(math.factorial(d[r]) / math.factorial(tmp) / math.factorial(d[r] - tmp))
    ans = list(ans.items())
    ans.sort(reverse=True, key = lambda x:x[0])
    print(ans[0][0])
    print(ans[0][1])
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    n = II()
    ans = inf
    for i in range(1, int(math.sqrt(n)) + 1):
        if not n % i:
            ans = min(ans, max(int(math.log(i, 10)), int(math.log(n // i, 10))))
    print(ans+1)
    return

#D
def D():
    n, a, b = LI()
    v = LI()
    v.sort(reverse=True)
    d = defaultdict(int)
    ans = defaultdict(int)
    for vi in v:
        d[vi] += 1
    for i in range(a, b + 1):
        res = v[:i]
        r = res[-1]
        tmp = res.count(r)
        ans[sum(res) / i] += math.factorial(d[r]) / math.factorial(tmp) / math.factorial(d[r] - tmp)
    ans = list(ans.items())
    ans.sort(reverse=True, key = lambda x:x[0])
    print(ans[0][0])
    print(int(ans[0][1]))
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    n = II()
    ans = inf
    for i in range(1, int(math.sqrt(n)) + 1):
        if not n % i:
            ans = min(ans, max(int(math.log(i, 10)), int(math.log(n // i, 10))))
    print(ans+1)
    return

#D
def D():
    n, a, b = LI()
    v = LI()
    v.sort(reverse=True)
    d = defaultdict(int)
    ans = defaultdict(int)
    for vi in v:
        d[vi] += 1
    for i in range(a, b + 1):
        res = v[:i]
        r = res[-1]
        tmp = res.count(r)
        ans[sum(res) / i] += math.factorial(d[r]) / math.factorial(tmp) / math.factorial(d[r] - tmp)
    ans = list(ans.items())
    ans.sort(reverse=True)
    print(ans[0][0])
    print(int(ans[0][1]))
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return

#C
def C():
    n = II()
    ans = inf
    for i in range(1, int(math.sqrt(n)) + 1):
        if not n % i:
            ans = min(ans, max(int(math.log(i, 10)), int(math.log(n // i, 10))))
    print(ans+1)
    return

#D
def D():
    n, a, b = LI()
    v = LI()
    v.sort(reverse=True)
    d = defaultdict(int)
    ans = defaultdict(int)
    for vi in v:
        d[vi] += 1
    for i in range(a, b + 1):
        res = v[:i]
        r = res[-1]
        tmp = res.count(r)
        ans[sum(res) / i] += math.factorial(d[r]) / math.factorial(tmp) / math.factorial(d[r] - tmp)
    ans = list(ans.items())
    ans.sort(reverse=True)
    print(ans[0][0])
    print(ans[0][1])
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,A,B = inputMap()
    v = inputList()
    
    mppping = {}
    for i in v:
        if i in mppping:
            mppping[i] += 1
        else:
            mppping[i] = 1
    
    v.sort()
    v.reverse()
    
    ans = 0
    cnt = 0
    ogi = []
    for i in range(A,B+1):
        tmp_arr = v[:i]
        tmp = sum(tmp_arr) / len(tmp_arr)
        
        if tmp > ans:
            ans = tmp
            ogi = tmp_arr
            
    print(ans)
    kazu = []
    for i,val in enumerate(ogi):
        kazu.append(mppping[val])
    
    cnt = 1
    flg = 0
    for i,val in enumerate(kazu):
        if flg > 0:
            flg -= 1
            continue
        cnt = cnt * val
        flg = val-1
        
    print(cnt)
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import collections
import math

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


N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())), reverse=True)
s = [0] + list(accumulate(v))
print("{0:.6f}".format(s[A] / A))
cou = collections.Counter(v[:])
t = 0
ans = 0
for i in v:
    if i > v[A-1]:
        t += 1
if t >= 1:
    print(cou[v[A-1]])
else:
    for i in range(A, min(B+1, cou[v[A-1]])+1):
        ans += combinations_count(cou[v[A-1]],i)
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import collections
import math

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


N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())), reverse=True)
s = [0] + list(accumulate(v))
print("{0:.6f}".format(s[A] / A))
cou = collections.Counter(v[:])
t = 0
ans = 0
for i in v:
    if i > v[A-1]:
        t += 1
if t >= 1:
    print(cou[v[A-1]])
else:
    for i in range(A, min(B+1, cou[v[A-1]]+1)):
        ans += combinations_count(cou[v[A-1]],i)
    print(ans)

Submission status: Wrong Answer

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

items.sort(reverse=True)

maxAvg = sum(items[:A]) / A

print(maxAvg)

fact = [1 for _ in range(N + 10)]

for i in range(1, N + 10):
    fact[i] = (fact[i - 1] * i)

def comb(n, r):
    if 0 < r < n:
        return fact[n] // fact[r] // fact[n - r]
    if r == 0 or r == n:
        return 1
    return 0


if items[0] == items[A - 1]:
    right = A - 1
    while right < N and items[right] == items[0]:
        right += 1
    ans = 0
    for take in range(A, right + 1):
        ans += comb(right, take)
    print(ans)
else:
    left = A - 1
    while left >= 0 and items[left] == items[A - 1]:
        left -= 1
    right = A - 1
    while right < N and items[right] == items[A - 1]:
        right += 1
    ans = comb(right - left - 1, A - left - 1)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = 0
    for i in range(A, B + 1):
        if i + num_replace_in_list > num_replace:
            break
        ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = 0
    for i in range(A, B + 1):
        if i + num_replace_in_list > num_replace:
            break
        ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

if replace * A != max_sum:
    ans = 1
    for i in range(A, N):
        if V[i] == replace:
            ans += 1
    print(ans)
    exit()

num_same = 0
for v in V:
    if v == replace:
        num_same += 1

ans = 0
for i in range(A, B + 1):
    if i > num_same:
        break
    ans += math.factorial(num_same) // (math.factorial(num_same - i) * math.factorial(i))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    return math.factorial(n) //(math.factorial(r) * math.factorial(n-r))

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
ave = (sum(v[:A]))/A
print (ave)

tmp_count = 1 #最初のA個の中にA番目と同じものが何個あるか
tmp = v[0]
for i in range(1, A):
    if v[i] == tmp:
        tmp_count += 1
    else:
        tmp = v[i]
        tmp_count = 1

total_count = tmp_count #全体でA番目と同じものが何個あるか
for i in range(A, N):
    if tmp == v[i]:
        total_count += 1
    else:
        break

ans = 0
if ave == tmp: #ここまで全て同じとき
    # print ('A')
    for i in range(A, total_count + 1):
        ans += conbination(total_count, i)
else:
    ans += conbination(total_count, tmp_count)

print (ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
s = list(Counter(v[:a]).items())
t = list(Counter(v).items())
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n] // fact[r] // fact[n-r]
ans = sum(v[:a])/a
print(ans)
cnt = 0
if len(s) == 1:
    for i in range(a,b+1):
        if t[0][1] >= i:
            cnt += comb(t[0][1],i)
else:
    for i,j in t:
        if i == s[-1][0]:
            cnt = comb(j,s[-1][1])
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
s = list(Counter(v[:a]).items())
t = list(Counter(v).items())
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n] // fact[r] // fact[n-r]
ans = sum(v[:a])/a
print(ans)
cnt = 0
if len(s) == 1:
    for i in range(a,b+1):
        if t[0][1] >= i:
            cnt += comb(t[0][1],i)
else:
    for i,j in t:
        if i == s[-1][0]:
            cnt += comb(j,s[-1][1])
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]/(fact[r]*fact[n-r])
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    l = min(b,c)
    for i in range(a,l+1):
        ans += comb(c,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
s = list(Counter(v[:a]).items())
t = list(Counter(v).items())
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]/(fact[r]*fact[n-r])
ans = sum(v[:a])/a
print(ans)
cnt = 1
if len(s) == 1:
    for i in range(a,b):
        if t[0][1] > i:
            cnt += comb(t[0][1],i)
else:
    for i,j in s:
        for k,l in t:
            if i == k:
                cnt *= comb(l,j)
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
s = list(Counter(v[:a]).items())
t = list(Counter(v).items())
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]/(fact[r]*fact[n-r])
ans = sum(v[:a])/a
print(ans)
cnt = 1
if len(s) == 1:
    for i in range(a,b):
        if t[0][1] > i:
            cnt += comb(t[0][1],i)
else:
    for i,j in s:
        for k,l in t:
            if i == k:
                cnt *= l
print(cnt)

Submission status: Wrong Answer

Solution code:
def comb(n,k): #nCkを出力する関数
    ans = [[1]]
    tem = []
    for i in range(1,n+1):
        tem = []
        for j in range(i+1):
            if(j==0 or j==i):
                tem.append(1)
            else:
                tem.append(ans[i-1][j-1]+ans[i-1][j])
        ans.append(tem)
    return ans[n][k] 

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

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a-1] < ans:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count0 = 0
        for i in range(b):
            if v[n-i-1] == v[n-1]:
                count0 = count0 + 1 
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(count0-x+1))//x
        for i in range(a,count0+1):
            c = c*(count0-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a-1] < ans:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count0 = 0
        for i in range(b):
            if v[n-i-1] == v[n-1]:
                count0 = count0 + 1 
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(n-x+1))//x
        for i in range(a,count0+1):
            c = c*(n-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a] < v[n-1]:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count0 = 0
        for i in range(b):
            if v[n-i-1] == v[n-1]:
                count0 = count0 + 1 
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(n-x+1))//x
        for i in range(a,count0+1):
            c = c*(n-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a] < v[n-1]:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count0 = 0
        for i in range(b):
            if v[n-i-1] == v[n-1]:
                count0 = count0 + 1 
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(n-x+1))//x
        for i in range(a,count0+1):
            c = c*(50-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
ans1 = 0
for i in range(a):
    ans1 = ans1 + v[n-1-i]
ans = ans1/a
if v[n-a] != v[n-a-1]:
    print(ans)
    print("1")
else:
    if v[n-a] < v[n-1]:
        count = 1
        for i in range(n-a):
            if v[i] == v[n-a]:
                count = count + 1
        print(ans)
        print(count)
    else:
        count = 0
        c = 1
        for x in range(1,a):
            c = (c*(n-x+1))//x
        for i in range(a,b+1):
            c = c*(50-i+1)//i
            count = count + c
        print(ans)
        print(count)

Submission status: Wrong Answer

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

    ans = ansMul // ansDiv
    return ans

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

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

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

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

v.sort()
v.reverse()

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

print(ans)
print(cnt)

Submission status: Wrong Answer

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

    ans = ansMul // ansDiv
    return ans

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

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

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

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

v.sort()
v.reverse()

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

print(ans)
print(cnt)