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:
N,A,B = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
v.sort()
v.reverse()
cum = [v[0]]

def comb(n, k):
    if k>n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for j in range(k):
        ans = ans// (j+1)
    return ans

for i in range(1,N):
    cum += [cum[i-1] + v[i]]
print('{:.10f}'.format(cum[A-1]/A))
target = v[A-1]
n = v.count(target)
fromk = v.index(target) - (A-1) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    ans = comb(n, fromk)
    print(ans)

Submission status: Wrong Answer

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

def comb(n, k):
    if k>n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for j in range(k):
        ans = ans// (j+1)
    return ans

for i in range(1,N):
    cum += [cum[i-1] + v[i]]
print('{:.6g}'.format(cum[A-1]/A))
target = v[A-1]
n = v.count(target)
fromk = v.index(target) - (A-1) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    ans = comb(n, fromk)
    print(ans)

Submission status: Wrong Answer

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

def comb(n, k):
    if k>n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for j in range(k):
        ans = ans// (j+1)
    return ans

for i in range(1,N):
    cum += [cum[i-1] + v[i]]
print(cum[A-1]/A)
target = v[A-1]
n = v.count(target)
fromk = v.index(target) - (A-1) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    ans = comb(n, fromk)
    print(ans)

Submission status: Wrong Answer

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

def comb(n, k):
    if k>n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for j in range(k):
        ans = ans// (j+1)
    return ans

for i in range(1,N):
    cum += [(cum[i-1] + v[i])/(i+1)]
print(cum[A-1])
target = v[A-1]
n = v.count(target)
fromk = v.index(target) - (A-1) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    ans = comb(n, fromk)
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from math import sqrt

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 = list(map(int, input().split()))
V = list(map(int, input().split()))

V.sort(reverse = True)

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

# A番目と一緒の数字の数（A個より外で）
cnt_ext = 0
for i in range(A,min(A+B,N)):
  if V[A-1] == V[i]:
    cnt_ext += 1
    
# A番目と一緒の数字の数（A個の中で）
cnt_int = 0
for i in range(0,A):
  if V[A-1] == V[i]:
    cnt_int += 1
    
#print(cnt_int, cnt_ext)
cnt_all = cnt_int + cnt_ext

ans = 0
for i in range(A,B):
  if cnt_ext < 0:
    break
  ans += cmb(cnt_all, cnt_int)
  cnt_int += 1
  cnt_ext -= 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] != v[i+1]:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] != v[i-1]:
            left = i
            break
    number = right - left + 1
    ans = 0
    if v[a-1] != v[a]:
        print(nCk(number,a-left))
        return
    if v[0] == v[a-1]:
        for e in range(a,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    if v[a-1] != v[a]:
        print(1)
        return
    cnt = 1
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] == v[i+1]:
            cnt += 1
        else:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] == v[i-1]:
            cnt += 1
        else:
            left = i
            break
    number = right - left + 1
    ans = 0
    if v[0] == v[a-1]:
        for e in range(a,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    if v[a-1] != v[a]:
        print(1)
        return
    cnt = 1
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] == v[i+1]:
            cnt += 1
        else:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] == v[i-1]:
            cnt += 1
        else:
            left = i
            break
    number = right - left + 1
    ans = 0
    if left == 0:
        for e in range(a,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    if v[a-1] != v[a]:
        print(1)
        return
    cnt = 1
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] == v[i+1]:
            cnt += 1
        else:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] == v[i-1]:
            cnt += 1
        else:
            left = i
            break
    number = right - left + 1
    ans = 0
    if left == 0:
        for e in range(1,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    if v[a-1] != v[a]:
        print(1)
        return
    cnt = 1
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] == v[i+1]:
            cnt += 1
        else:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] == v[i-1]:
            cnt += 1
        else:
            left = i
            break
    number = right - left + 1
    ans = 0
    for e in range(max(1,a-left),number+1 - max(n-b+1,n-right-1)):
        ans += nCk(number,e)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
from collections import defaultdict, Counter

def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d
MOD = 10**9 + 7
INF = 10**10

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

def main():
    n,a,b = getlist()
    nums = getlist()

    cnt = Counter(nums)

    cnt = sorted(cnt.items(), key=lambda x: -x[0])
    # print(cnt)
    ans = 0
    tmp_max = 0
    res = 0
    for i in range(a, b+1):
        remain = i
        acc_val = 0
        for it in cnt:
            if it[1] <= remain:
                remain -= it[1]
                acc_val += it[1] * it[0]

            else:
                acc_val += remain * it[0]
                cmb = comb(it[1], remain)
                mean = acc_val / i
                res += comb(50, i)
                if mean == tmp_max:
                    ans += cmb
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = cmb
                # print(mean, acc_val, ans, res)
                break

            if remain == 0:
                mean = acc_val // i
                if mean == tmp_max:
                    ans  += 1
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = 1

                break
    print(tmp_max)
    print(ans)

    # res = 0
    # for i in range(1, 51):
    #     res += comb(50, i)
    #
    # print(res)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Submission status: Wrong Answer

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

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

def check():
    N,A,B = [int(i) for i in input().split()]
    V = sorted([int(i) for i in input().split()], reverse=True)
    mean = sum(V[:A])/A
    print(mean)
    count_dict = dict(Counter(V))
    
    max_v_cnt = list(count_dict.values())[0]
    if max_v_cnt > A:
        cnt = 0
        for i in range(A,max_v_cnt+1):
            cnt += cmb(max_v_cnt, i)
    else:
        for v, c in count_dict.items():        
            if A - c < 0:
                last_c = c
                break
            A -= c    
        cnt = cmb(last_c, A)
    print(cnt)

check()

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
def check():
    N,A,B = [int(i) for i in input().split()]
    V = sorted([int(i) for i in input().split()], reverse=True)
    mean = sum(V[:A])/A
    print(mean)
    count_dict = dict(Counter(V))
    
    max_v_cnt = list(count_dict.values())[0]
    if max_v_cnt > A:
        cnt = 0
        for i in range(A,max_v_cnt+1):
            cnt += comb(max_v_cnt, i)
    else:
        for v, c in count_dict.items():        
            if A - c < 0:
                last_c = c
                break
            A -= c    
        cnt = comb(last_c, A)
    print(cnt)
 
check()

Submission status: Wrong Answer

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

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

def check():
    N,A,B = [int(i) for i in input().split()]
    V = sorted([int(i) for i in input().split()], reverse=True)
    mean = sum(V[:A])/A
    print(mean)
    count_dict = dict(Counter(V))
    
    for v, c in count_dict.items():
        if A - c < 0:
            last_c = c
            break
        A -= c    
    print(cmb(last_c, A))

check()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

N, A, B = map(int, input().split())
V = list(map(int, input().split()))
MOD = 10 ** 100 + 7

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
 
def comb(n, r, mod):
  if r < 0 or r > n:
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod
 
for i in range(2, 50 + 1):
  g1.append((g1[-1] * i) % MOD)
  inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
  g2.append((g2[-1] * inverse[-1]) % MOD)

V = sorted(V)[::-1]
counter = defaultdict(int)

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

for v in V:
  if v >= V[A]:
    counter[v] += 1
  else:
    break
counter = list(counter.items())
counter = sorted(counter)[::-1]
 
if len(counter) == 1:
  answer = 0
  for i in range(A, min(B + 1, counter[0][1] + 1)):
    answer += comb(counter[0][1], i, MOD)
  print(answer)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
def COMB(a,b):
	if b > (a-b):
		b = a-b
	ans = 1
	for i in range(0,b):
		ans *= (a-i)
		ans /= (b-i)

	return int(ans)

if __name__ == '__main__':
	N, A, B = map(int, input().split())
	v_lst = [int(p) for p in input().split()]

	v_lst.sort(reverse = True)

	count = 0

	for i in range(0,B-A+1):
		lst = v_lst[0:A+i]
		mean = sum(lst)/len(lst)
		if i == 0:
			nxt_mean = mean
		if mean == nxt_mean:
			a = v_lst.count(min(lst))
			b = lst.count(min(lst))
			count += COMB(a,b)
		else:
			break
		nxt_mean = mean

	print("{:.6f}".format(nxt_mean))
	print(count)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def nCr(n, r):
    return fac[n] // fac[r] // fac[n - r]

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

def main():
    n, a, b = MI()
    vv = LI()
    vv.sort(reverse=True)
    s = sum(vv[:a])
    tot = vv.count(vv[a - 1])
    l = vv[:a].count(vv[a - 1])
    if l == a:
        p = 0
        for r in range(l, tot + 1):
            p += nCr(tot, r)
    else:
        p = nCr(tot, l)
    print(s / a)
    print(p)

main()

Submission status: Wrong Answer

Solution code:
from math import factorial
def comb(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
x = V[-1]
ans = 0
for i in range(1,A+1):
    ans += V[-i]
    x = V[-i]
ans = ans/A
print(ans)
count = 0
import bisect
y = N - bisect.bisect(V,x)
if x == V[-1]:
    n = V.count(x)
    for i in range(A,min(B,V.count(x))+1):
        z = i - y
        count += comb(n,z)
else:
    z = A - y
    n = V.count(x)
    count += comb(n,z)
print(int(count))

Submission status: Wrong Answer

Solution code:
from math import factorial
def comb(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
x = V[-1]
ans = 0
for i in range(1,A+1):
    ans += V[-i]
    x = V[-i]
ans = ans/A
print(ans)
count = 0
import bisect
y = N - bisect.bisect(V,x)
if x == V[-1]:
    n = V.count(x)
    for i in range(A,min(B,V.count(x))+1):
        z = i - y
        count += comb(n,z)
else:
    z = A - y
    n = V.count(x)
    count += comb(n,z)
print(count)

Submission status: Wrong Answer

Solution code:
# D - Maximum Average Sets

from math import factorial

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

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

print(sum(v[:A]) / A)
for i in reversed(range(A, B)):
    if v[i] == v[0]:
        ans = 0
        for j in range(A, i+2):
            ans += comb(i+1, j)
        print(ans)
        break
else:
    print(v.count(v[A]))

Submission status: Wrong Answer

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

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

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + comb(n, kosuu, exact=True))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Wrong Answer

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

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

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + comb(n, kosuu, exact=True))
  
  ave = sum(List[:A])/A
  print(ave)
  print(ans)

Submission status: Wrong Answer

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

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

mini = List[A-1]
ans = 0



num = List.count(List[A-1])
List = sorted(List)
num2 = N - bisect.bisect_right(List,List[A-1])
List = sorted(List, reverse=True)
  
if List[0] != List[A-1]:
  B = A
for i in range(B-A+1):
  n = num
  kosuu = A + i - num2
  ans  = ans + comb(n, kosuu, exact=True)
  
ave = sum(List[:A])/A
print(ave)
print(ans)

Submission status: Wrong Answer

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

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

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = ans + comb(n, kosuu, exact=True)
  
  ave = sum(List[:A])/A
  print(ave)
  print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

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

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = 1
  
  ave = sum(List[:A])/A
  print(ave)
  print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

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

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)
 
def comb(n,r):
    return perm(n,r)//factorial(r)


n,a,b=nm()
v=sorted(nl(), reverse=True)

if v[0]==v[a-1]:
    n = 0
    for vv in v:
        if vv!=v[0]: break
        n += 1

    ans = 0
    for k in range(a, min(b,n)+1):
        ans += comb(n, k)

else:
    n = k = 0
    for i,vv in enumerate(v):
        if v==v[a-1]:
            if i<a: k += 1
            n += 1
    ans = comb(n,k)

print(sum(v[:a])/a)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            #one_flg=True
            ans=1
            print(value/cnt)
            print(ans)
            exit()
        if b>=v:
            value+=k*v
            cnt+=v
            b-=v
        elif b<v:
            if b==0 and v==1:
                # one_flg=True
                ans=1
                print(value/cnt)
                print(ans)
                exit()
            for i in range(a,min(b,v)):
                value+=k*a
                cnt+=a
                nn=v
                kk=a
                ans=comb(nn, kk)
            break
# if one_flg:
#     ans=1
print(value/cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

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

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        for i in range(a,min(b,v)):
            value+=k*a
            cnt+=a
            nn=v
            kk=a
            ans=comb(nn, kk)
        break
if one_flg:
    ans=1
print(value/cnt)
print(ans)