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:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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


dp = [[0 for j in range(B+1)] for i in range(N)]
for i in range(N):
    dp[i][0] = max(v[:i+1])

for i in range(N-1):
    for j in range(min(B,i+1)):
        dp[i+1][j+1] = max(dp[i][j+1],(dp[i][j]*(j+1)+v[i+1])/(j+2))

ans = max(dp[-1][A-1:B+1])
print(ans)

v.sort()
v.reverse()

cnt = 0
if v[0] != v[A-1]:
    m = v.count(v[A-1])
    n = v[:A+1].count(v[A-1])
    cnt = math.factorial(m)//(math.factorial(n)*math.factorial(m-n))
else:
    m = v.count(v[0])
    n = A
    for i in range(n,min(m+1,B+1)):
        cnt += math.factorial(m)//(math.factorial(i)*math.factorial(m-i))

print(cnt)

Submission status: Wrong Answer

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

items = V[:]

items = sorted(items, reverse=True)
sub_items = items[:A]
ave = sum(sub_items)/len(sub_items)
rest_items = items[A:]

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

if ave != sub_items[0]:
    # nCr
    r = sub_items.count(sub_items[-1])
    n = rest_items.count(sub_items[-1]) + r
    print(n, r)
    pattern = combinations_count(n, r)
else:
    n = items.count(ave)
    pattern = 0
    for r in range(A, min(n+1, B+1)):
        pattern += combinations_count(n, r)


print(ave)
print(pattern)

Submission status: Wrong Answer

Solution code:
import math
def f(n):
    return math.factorial(n)
n,a,b=map(int,input().split())
V=[int(i) for i in input().split()]
V.sort()
if n==a:
  print(sum(V)/a)
  print(1)
else:
  ans=sum(V[n-a:])/a
  count1=V[n-a:].count(V[n-a])
  count2=V[:n-a].count(V[n-a])
  print(ans)
  if count1==a:
    ans2=0
    for i in range(min(count2+1,b-a+1)):
      ans2+=f(count1+count2)/f(count1+i)/f(count2-i)
    print(int(ans2))
  else:
    print(int(f(count1+count2)/f(count1)/f(count2)))

Submission status: Wrong Answer

Solution code:
import math
def f(n):
    return math.factorial(n)
n,a,b=map(int,input().split())
V=[int(i) for i in input().split()]
V.sort()
if n==a:
  print(sum(V)/a)
  print(1)
else:
  ans=sum(V[n-a:])/a
  count1=V[n-a:].count(V[n-a])
  count2=V[:n-a].count(V[n-a])
  print(ans)
  if count1==a:
    ans2=0
    for i in range(min(count2+1,b-a+1)):
      ans2+=int(f(count1+count2)/f(count1+i)/f(count2-i))
    print(ans2)
  else:
    print(int(f(count1+count2)/f(count1)/f(count2)))

Submission status: Wrong Answer

Solution code:
import math
def f(n):
    return math.factorial(n)
n,a,b=map(int,input().split())
V=[int(i) for i in input().split()]
V.sort()
if n==a:
  print(sum(V)/a)
  print(1)
else:
  ans=sum(V[n-a:])/a
  count1=V[n-a:].count(V[n-a])
  count2=V[:n-a].count(V[n-a])
  print(ans)
  ans2=0
  for i in range(min(count2+1,b-a)):
    ans2+=int(f(count1+count2)/f(count1+i)/f(count2-i))
  print(ans2)

Submission status: Wrong Answer

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

v.sort(reverse=1)

V = v[A-1]
print(sum(v[:A]) / A)

before = 0
after = 0
all = False
for i in range(A):
    if v[i] == V:
        if i == 0:
            all = True
        before = A - i
        break
for i in range(A, N):
    if v[i] == V:
        after += 1
    else:
        break

def C(n,k):
    ans = 1
    for i in range(k):
        ans *= (n-i)
    for i in range(1, k+1):
        ans //= i
    return ans

if all:
    ans = 0
    for i in range(before, before+after+1):
        ans += C(before+after, i)
    print(ans)
else:
    print(C(before+after, before))

Submission status: Wrong Answer

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


V.sort(reverse=True)
print(sum(V[:A]) / A)


Ath_CNT = V.count(V[A - 1])
if max(V) == V[A - 1]:
    ans = 0
    for k in range(A, B + 1):
        ans += comb(Ath_CNT, k, 1)
else:
    ans = comb(Ath_CNT, A, 1)
print(max(ans, 1))

Submission status: Wrong Answer

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


V.sort(reverse=True)
print(sum(V[:A]) / A)


Ath_CNT = V.count(V[A - 1])
if max(V) == V[A - 1]:
    ans = 0
    for k in range(A, max(B, Ath_CNT) + 1):
        ans += comb(Ath_CNT, k, 1)
else:
    ans = comb(Ath_CNT, A, 1)
print(max(ans, 1))

Submission status: Wrong Answer

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


V.sort(reverse=True)
print(sum(V[:A]) / A)


Ath_CNT = V.count(V[A - 1])
if max(V) == V[A - 1]:
    ans = 0
    for k in range(A, Ath_CNT + 1):
        ans += comb(Ath_CNT, k, 1)
else:
    ans = comb(Ath_CNT, A, 1)
print(max(ans, 1))

Submission status: Wrong Answer

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

v.sort()
v.reverse()

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

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

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

Submission status: Wrong Answer

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

v.sort()
v.reverse()

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

c = v.count(v[a])
d = v[:a].count(v[a])

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

Submission status: Wrong Answer

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

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

n,a,b,*v=map(int,open(0).read().split())
v=sorted(Counter(v).items(),reverse=1,key=lambda x:x[0])
vindex=[0]+list(accumulate(V for K,V in v))+[float("inf")]
#print(v,vindex)
lower=vindex[bisect_left(vindex,a)-1]
upper=vindex[bisect_left(vindex,a)]
count=0
ans=0

if a<=vindex[1]:
    ans=0
    for i in range(a,vindex[1]+1):
        ans+=cmb(vindex[1],i)
    print(float(v[0][0]))
    print(ans)

else:
    for s,t in v:
        count+=t
        if count>lower:
            ans+=s*(a-lower)
            break
        else:
            ans+=s*t
    print(ans/a)
    print(cmb(upper-lower,a-lower))

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
    if v[i]>m:
        cnt+=1
    else:
        break

def fact(n):
    if n==0 or n==-1:
        return 1
    return fact(n-1)*n
def comb(n,k):
    return fact(n)//fact(n-k)//fact(k)

    
ans=0
#print('mm,cnt',mm,cnt)
for i in range(min(mm+cnt-a,b-cnt)+1):
    ans+=comb(mm,a-cnt+i)
    #print(i,ans)
if m!=v[0]:
    ans=comb(mm,a-cnt)
if cnt>=a:
    ans=1
print(sum(v[0:a])/a)
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
    if v[i]>m:
        cnt+=1
    else:
        break

def fact(n):
    if n==0 or n==-1:
        return 1
    return fact(n-1)*n
def comb(n,k):
    return fact(n)//fact(n-k)//fact(k)

    
ans=0
#print('mm,cnt',mm,cnt)
for i in range(min(mm+cnt-a,b-cnt)+1):
    ans+=comb(mm,a-cnt+i)
    #print(i,ans)
if m!=v[0]:
    ans=comb(mm,a-cnt)
print(sum(v[0:a])/a)
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
    if v[i]>m:
        cnt+=1
    else:
        break

def fact(n):
    if n==0 or n==-1:
        return 1
    return fact(n-1)*n
def comb(n,k):
    return fact(n)//fact(n-k)//fact(k)

    
ans=0
for i in range(min(mm+cnt-a,b-cnt)+1):
    ans+=comb(mm,a-cnt+i)
print(sum(v[0:a])/a)
print(ans)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse = True)
set_v = set()
cnt_v = []
for i in v:
    if i not in set_v:
        set_v.add(i)
        cnt_v.append(i)

from collections import Counter
from operator import itemgetter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(v)
sum = 0
cnt = 0
num = 0
if c[v[0]] >= a:
    print(float(v[0]))
    for i in range(a,min(b,c[v[0]]) + 1):
        print(i)
        num += combinations_count(c[v[0]], i)
    print(num)
    exit()
for i in cnt_v:
    if c[i] < a:
        a -= c[i]
        b -= c[i]
        sum += c[i]*i
        cnt += c[i]
    else:
        sum += i*a
        cnt += a
        print(sum/cnt)
        print(combinations_count(c[i],a))
        break

Submission status: Wrong Answer

Solution code:
n, a, b = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse = True)
set_v = set()
cnt_v = []
for i in v:
    if i not in set_v:
        set_v.add(i)
        cnt_v.append(i)

from collections import Counter
from operator import itemgetter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(v)
sum = 0
cnt = 0
num = 0
if c[v[0]] >= b:
    print(float(v[0]))
    for i in range(a,b+1):
        num += combinations_count(n, i)
    print(num)
    exit()
for i in cnt_v:
    if c[i] < a:
        a -= c[i]
        b -= c[i]
        sum += c[i]*i
        cnt += c[i]
    else:
        sum += i*a
        cnt += a
        print(sum/cnt)
        print(combinations_count(c[i],a))
        break

Submission status: Wrong Answer

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

from collections import Counter
from operator import itemgetter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(v)
sum = 0
cnt = 0
num = 0
if c[v[0]] >= b:
    print(float(v[0]))
    for i in range(a,b+1):
        num += combinations_count(n, i)
    print(num)
    exit()
for i in c:
    if c[i] < a:
        a -= c[i]
        b -= c[i]
        sum += c[i]*i
        cnt += c[i]
    else:
        sum += i*a
        cnt += a
        print(sum/cnt)
        print(combinations_count(c[i],a))
        break

Submission status: Wrong Answer

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

from collections import Counter
from operator import itemgetter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(v)
sum = 0
cnt = 0
num = 0
if c[v[0]] >= b:
    print(float(v[0]))
    for i in range(a,b+1):
        num += combinations_count(n, i)
    print(num)
    exit()
for i in c:
    print(i)
    if c[i] < a:
        a -= c[i]
        b -= c[i]
        sum += c[i]*i
        cnt += c[i]
    else:
        sum += i*a
        cnt += a
        print(sum/cnt)
        print(combinations_count(c[i],a))
        break

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.7f}".format(sum(v[0:a])/a))
    print(int(comb(total, cnt1)))

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    if k == 0 or k == n:
        return 1
    return comb(n-1, k) + comb(n-1, k-1)

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.6f}".format(sum(v[0:a])/a))
    print(int(comb(total, cnt1)))

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.6f}".format(sum(v[0:a])/a))
    print(int(comb(total, cnt1)))

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1

    
        
    

    print("{:.6f}".format(sum(v[0:a])/a))
    print(comb(total, cnt1))


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    meanmax = 0 
    maxnum = -1
    for i in range(a, b+1):
        if sum(v[0:i])/i > meanmax:
            meanmax = sum(v[0:i])/i
            maxnum = i
    
    num = v[maxnum-1]

    cnt = 0
    for i in v:
        if i == num:
            cnt += 1



    print("{:.6f}".format(meanmax))
    print(cnt)


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    meanmax = 0 
    maxnum = -1
    for i in range(a, b+1):
        if sum(v[0:i])/i > meanmax:
            meanmax = sum(v[0:i])/i
            maxnum = i
    
    num_set = set()

    for i in range(0, maxnum):
        num_set.add(v[i])

    num_cnt = {}

    for i in v:
        if i in num_set:
            if i in num_cnt:
                num_cnt[i] += 1
            else:
                num_cnt[i] = 1

    ans = 1
    for k,v in num_cnt.items():
        ans *= v
    

    print("{:.6f}".format(meanmax))
    print(v)


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    meanmax = 0 
    maxnum = -1
    for i in range(a, b+1):
        if sum(v[0:i])/i > meanmax:
            meanmax = sum(v[0:i])/i
            maxnum = i
    
    num_set = set()

    for i in range(0, maxnum):
        num_set.add(v[i])

    num_cnt = {}

    for i in v:
        if i in num_set:
            if i in num_cnt:
                num_cnt[i] += 1
            else:
                num_cnt[i] = 1

    ans = 1
    for k,v in num_cnt.items():
        ans *= v
    
    print(meanmax)
    print(v)



solve()

Submission status: Wrong Answer

Solution code:
from math import factorial
from itertools import accumulate
from collections import Counter
N, a, b = [int(item) for item in input().split()]
v = sorted([int(item) for item in input().split()], reverse=True)

vsum = list(accumulate(v))
vcounts = []
for i in range(N):
    vcounts.append(Counter(v[:i+1]))

ans = 0
ans_count = 0
for i in range(a, b+1):
    val = vsum[i-1] / i
    if val > ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count = factorial(n) / factorial(r) / factorial(n-r)
        ans = val
    elif val == ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count += factorial(n) / factorial(r) / factorial(n-r)
print(ans)
print(int(ans_count))

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(A, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        num += math.factorial(n) // (math.factorial(n - A) * math.factorial(A))
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(A, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        x = min(n, B)
        for i in range(A, x + 1):
            num += math.factorial(n) // (math.factorial(n - i) * math.factorial(i))
        break
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(A, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        x = min(n, B)
        for i in range(A, x):
            num += math.factorial(n) // (math.factorial(n - i) * math.factorial(i))
        break
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(A, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        for i in range(n - A, A + 1):
            num += math.factorial(n) // (math.factorial(n - i) * math.factorial(i))
        break
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(1, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        for i in range(1, A + 1):
            num += math.factorial(n) // (math.factorial(n - i) * math.factorial(i))
        break
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Submission status: Wrong Answer

Solution code:
#D問題

#factorial(階乗)
def factorial(facn):
    ret=1
    for i in range(facn):
        ret*=(i+1)
    return ret
#combination(組み合わせC)
def comb(comb1,comb2):
    x=min(comb1,comb2)
    y=max(comb1,comb2)
    bunshi=factorial(y)
    bunbo=factorial(x)*factorial(y-x)
    return int(bunshi/bunbo)

N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
dp=[0 for i in range(N)]
for i in range(A):
    if i == 0:
        dp[0]=v[0]
    else:
        dp[i]=dp[i-1]+v[i]
MAX=dp[A-1]/A
V=v[A-1]
left=v[:A]
right=v[A:]
LV=left.count(V)
RV=right.count(V)
if V == v[0]:
    Vsum=LV+RV
    com=0
    for i in range(1,Vsum+1):
        com+=comb(Vsum,i)        
else:
    com=comb(LV+RV,LV)
print(MAX)
print(com)

Submission status: Wrong Answer

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

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

last = VA[-1]
x = VA.count(last)
z = V.count(last)

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

if V.count(V[0]) > A:
    ans = 0
    for i in range(A, B + 1):
        ans += comb(z, i)
else:
    ans = comb(z, x)
    
print(ans)

Submission status: Wrong Answer

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

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

last = VA[-1]
x = VA.count(last)
z = V.count(last)

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

if V.count(V[0]) == N:
    ans = 0
    for i in range(A, B + 1):
        ans += comb(z, i)
else:
    ans = comb(z, x)
    
print(ans)

Submission status: Wrong Answer

Solution code:
#D問題

#factorial(階乗)
def factorial(facn):
    ret=1
    for i in range(facn):
        ret*=(i+1)
    return ret
#combination(組み合わせC)
def comb(comb1,comb2):
    x=min(comb1,comb2)
    y=max(comb1,comb2)
    bunshi=factorial(y)
    bunbo=factorial(x)*factorial(y-x)
    return int(bunshi/bunbo)

N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
dp=[0 for i in range(N)]
for i in range(A):
    if i == 0:
        dp[0]=v[0]
    else:
        dp[i]=dp[i-1]+v[i]
MAX=dp[A-1]/A
V=v[A-1]
left=v[:A]
right=v[A:]
LV=left.count(V)
RV=right.count(V)
com=comb(LV+RV,LV)
print(MAX)
print(com)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
try:
    from scipy.special import comb
except ImportError:
    from scipy.misc import comb

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

    m_ave = sum(V[:A]) / A
    b = A
    while b < B:
        if V[0] == V[b]:
            b += 1
        else:
            break

    print(A, b)

    if A == b:
        ans = 1
        c = Counter(V[:A])
        d = Counter(V)
        for key in c.keys():
            n = d[key]
            r = c[key]
            ans *= comb(n, r, exact=True)

    else:
        d = Counter(V)
        key = V[0]
        n = d[key]
        ans = 0
        for r in range(A, b+1):
            ans += comb(n, r, exact=True)

    print(m_ave)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
d = {}

def nCr(n, r):
    if n < r:
        return 0
    if n == r or r == 0:
        return 1
    if (n, r) in d:
        return d[(n, r)]
    d[(n, r)] = nCr(n, r - 1) + nCr(n - 1, r - 1)
    return d[(n, r)]

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    v = sorted((int(s) for s in input().split()), reverse=True)
    print(sum(v[:a]) / a)
    x = v.count(v[a - 1])
    print(nCr(x, v[:a].count(v[a - 1])) if v[0] > v[a - 1] else sum(nCr(x, i) for i in range(a, b + 1)))

Submission status: Wrong Answer

Solution code:
def combination(n: int, r: int)->int:
    if r == 0 or n == r:
        return 1
    return combination(n-1, r-1) + combination(n-1, r)


def maximum_average_sets(N: int, A: int, B: int, V: list)->tuple:
    sorted_v = sorted(V, key=lambda v: -v)
    ave = sum(sorted_v[:A]) / A
    num = combination(sorted_v.count(
        sorted_v[A-1]), sorted_v[:A].count(sorted_v[A-1]))
    return ave, num


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    V = [int(s) for s in input().split()]
    ave, num = maximum_average_sets(N, A, B, V)
    print(ave)
    print(num)

Submission status: Wrong Answer

Solution code:
# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

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

V.sort(reverse=True)

ave = sum(V[:A])/A
cnt = 0
last = V[A-1]
note = -1
for v in V:
    if v > last:
        note += 1
    if v == last:
        cnt += 1

pat = 0
if V[0] == last:
    for i in range(1,B-A+2):
        if i > cnt:
            break
        pat += comb(cnt,i)
else:
    pat = comb(cnt,A-note)

print(ave)
print(pat)

Submission status: Wrong Answer

Solution code:
# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

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

V.sort(reverse=True)

ave = sum(V[:A])/A
cnt = 0
last = V[A-1]
for v in V[A-1:]:
    if v == last:
        cnt += 1
    else:
        break
pat = 0
if V[0] == last:
    for i in range(1,B-A+2):
        if i > cnt:
            break
        pat += comb(cnt,i)
else:
    pat = cnt

print(ave)
print(pat)

Submission status: Wrong Answer

Solution code:
# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

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

V.sort(reverse=True)

ave = sum(V[:A])/A
cnt = 0
last = V[A-1]
for v in V[A-1:]:
    if v == last:
        cnt += 1
    else:
        break
pat = 0
if ave == last:
    for i in range(1,B-A+2):
        if i > cnt:
            break
        pat += comb(cnt,i)
else:
    pat = cnt

print(ave)
print(pat)

Submission status: Wrong Answer

Solution code:
# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

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

V.sort(reverse=True)
ave = 0
value = 0
num = 0
for i,v in enumerate(V):
    if num < A or ave < (value+v)/(num+1):
        value += v
        num += 1
    if num == A:
        note = i
        ave = value / num
        break
cnt = 0
last = V[note]
for v in V[note:]:
    if v == last:
        cnt += 1

ans = 0
if ave == last:
    for i in range(A,B+1):
        if i > cnt:
            break
        ans += comb(cnt,i)
else:
    ans = comb(cnt,1)

print(ave)
print(ans)

Submission status: Wrong Answer

Solution code:
f = 55 * [0]
f[0] = 1
for i in range(1, 51):
	f[i] = i * f[i - 1]	

foo = input().split()
n = int(foo[0])
k = int(foo[1])
bar = input().split()
a = len(bar) * [0]
for i in range(len(bar)):
	a[i] = int(bar[i])

a.sort()
a = a[::-1]
b = list(dict.fromkeys(a))
mapa1 = {}
mapa2 = {}
for i in range(len(b)):
	mapa1[b[i]] = 0
	mapa2[b[i]] = 0
for i in range(n):
	mapa1[a[i]] += 1
suma = 0
c = []
for i in range(k):
	mapa2[a[i]] += 1
	c.append(a[i]);
	suma += a[i]
c = list(dict.fromkeys(c))
c.sort()
c = c[::-1]
ways = 1
for i in range(len(c)):
	nm = mapa1[c[i]]
	kk = mapa2[c[i]] 

	ways *= f[nm] / (f[kk] * (f[nm - kk]))	

print("%.9f" % (suma / k));
print(int(ways))

Submission status: Wrong Answer

Solution code:
f = 55 * [0]
f[0] = 1
for i in range(1, 51):
	f[i] = i * f[i - 1]	

foo = input().split()
n = int(foo[0])
k = int(foo[1])
bar = input().split()
a = len(bar) * [0]
for i in range(len(bar)):
	a[i] = int(bar[i])

a.sort()
a = a[::-1]
b = list(dict.fromkeys(a))
mapa1 = {}
mapa2 = {}
for i in range(len(b)):
	mapa1[b[i]] = 0
	mapa2[b[i]] = 0
for i in range(n):
	mapa1[a[i]] += 1
suma = 0
c = []
for i in range(k):
	mapa2[a[i]] += 1
	c.append(a[i]);
	suma += a[i]
c = list(dict.fromkeys(c))
c.sort()
c = c[::-1]
ways = 1
for i in range(len(c)):
	nm = mapa1[c[i]]
	kk = mapa2[c[i]] 
	ways *= f[nm] // (f[kk] * (f[nm - kk]))	

print("%.9f" % (suma / k));
print(ways)

Submission status: Wrong Answer

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

V.sort(reverse=True)

mean = sum(V[:A]) / A
mean = float(mean)

print(mean)


def fact(n):
    if n == 0:
        return 1
    if n == 1:
        return 1
    return fact(n-1) * n

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

from collections import Counter
c = Counter(V)
n = c[V[0]]


if V[0] != V[A-1]:
    n = c[V[A-1]]
    if n > 1:
        print(n); exit()
    else:
        print(1); exit()

if V[0] == V[A-1]:
    ans = 0
    for i in range(A, min(n+1, B+1)):
        ans += comb(n, i)

    print( ans )