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

from collections import Counter
from itertools import combinations

def factorial(start, N):
    ans = 1
    for i in range(start, N+1):
        ans *= i
    return ans

def choose(n, m):
    a = factorial(n-m+1, n)
    b = factorial(1, m)
    return a/b

def Main(N, A, B, V):
    V.sort()
    V.reverse()
    counter_V = Counter(V)
    V_A = V[A-1]
    count_VA = counter_V[V_A]
    V_begin = 0
    V_end = N-1
    for i in range(N):
        if V[i] == V_A:
            V_begin = min(V_begin, i)
        elif V[i] < V_A:
            V_end = i-1
            break
    V_edge = V_end
    if V[V_end] == V[B-1]:
        V_edge = B-1
    choose_num = 1
    for i in range(A, V_edge+1):
        choose_num += choose(V_end-V_begin+1, i-V_begin)
    return sum(V[:A])/A, choose_num
                     
ave, choose_num = Main(N, A, B, V)
print(ave)
print(choose_num)

Submission status: Wrong Answer

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

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

if len(set(v)) == 1:
    print(1)
    print(1125899906842623)
    exit()

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

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

Submission status: Wrong Answer

Solution code:

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

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

if len(set(v)) == 1 and len(v) > 1:
    print(1)
    print(1125899906842623)
    exit()

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


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

Submission status: Wrong Answer

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse=True)

if len(set(v)) == 1:
    print(v[0])
    print(2**B-2**(A-1))
    exit()

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


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

print(cmb(m,n))

Submission status: Wrong Answer

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse=True)

if len(set(v)) == 1:
    print(v[0])
    print(2**B-2**A)
    exit()

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


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

print(cmb(m,n))

Submission status: Wrong Answer

Solution code:
def combination(n,r,mod=10**20+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod

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

if len(set(v)) == 1:
    print(v[0])
    print(2**len(v)-1)
    exit()

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


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

print(combination(m,n))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

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

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

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

total = 0
pattern = 0

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

Submission status: Wrong Answer

Solution code:
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

v.sort(reverse=True)
pre_sum=sum(v[:a])
if len(set(v))==1:
    print(pre_sum/a)
    s=0
    for i in range(b):
        s+=2**i
    print(s)

elif len(set(v[:a]))==a:
    print(pre_sum/a)
    print(1)

else:
    mo=v[a-1]
    c=v.count(mo)
    ind=v.index(mo)
    k=ind
    print(a-k)
    print(pre_sum/a)
    print(combinations_count(c, a-k))

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
pre_sum=sum(v[:a-1])
pre_sum+=v[a-1]
k=v.count(v[a-1])
print(pre_sum/a)
print(k)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from bisect import bisect_right as br
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
count = Counter(v)
v.sort()
c = 0

ans = sum(v[-a:])
fact = [1,1]
 
for i in range(2,n+2):
    fact.append((fact[-1]*i))
    
 
def nCr(n,r):
    if r > n:
        return 0
    else: 
        return fact[n]/fact[r]/fact[n-r]
for i in range(a,b+1):
    if sum(v[-i:])*a == ans*i:
        m = v[-i]
        if count[m] == 1:
            c += 1
        else:
            index = br(v,m)
            c += nCr(count[m],index-(n-i))
print(ans/a)
print(int(c))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from bisect import bisect_right as br
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
count = Counter(v)
v.sort()
c = 0
l = [0]*n
for i in range(a,b+1):
    
    l[i-1] = sum(v[-i:])/i

ans = max(l)
fact = [1,1]
 
for i in range(2,n+2):
    fact.append((fact[-1]*i))
    
 
def nCr(n,r):
    if r > n:
        return 0
    else: 
        return fact[n]/fact[r]/fact[n-r]
for i in range(n):
    if l[i] == ans:
        m = v[-i-1]
        if count[m] == 1:
            c += 1
        else:
            index = br(v,m)
            c += nCr(count[m],index-(n-1-i))
print(ans)
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from bisect import bisect_right as br
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
count = Counter(v)
v.sort()
c = 0
l = [0]*n
for i in range(a,b+1):
    
    l[i-1] = sum(v[-i:])/i

ans = max(l)
fact = [1,1]
 
for i in range(2,n+2):
    fact.append((fact[-1]*i))
    
 
def nCr(n,r):
    if r > n:
        return 0
    else: 
        return fact[n]/fact[r]/fact[n-r]
for i in range(n):
    if l[i] == ans:
        m = v[-i-1]
        if count[m] == 1:
            c += 1
        else:
            index = br(v,m)
            c += nCr(count[m],index-(n-1-i))
print(ans)
print(int(c))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

# Combination
MOD = 10**17+3
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
arr = V[:A]
se = set()
mi = 10**18
dic2 = defaultdict(int)
tot = 0
for a in arr:
    tot += a
    dic2[a] += 1
    se.add(a)
    if a < mi:
        mi = a
dic = defaultdict(int)
for v in V:
    dic[v] += 1
if len(se) == 1:
    ans = 0
    for i in range(1, B+1):
        ans += comb(dic[mi], i)
else:
    ans = comb(dic[mi], dic2[mi])
print(tot/A)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

# Combination
MOD = 10**18+3
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
arr = V[:A]
se = set()
mi = 10**18
dic2 = defaultdict(int)
tot = 0
for a in arr:
    tot += a
    dic2[a] += 1
    se.add(a)
    if a < mi:
        mi = a
dic = defaultdict(int)
for v in V:
    dic[v] += 1
if len(se) == 1:
    ans = 0
    for i in range(1, B+1):
        ans += comb(dic[mi], i)
else:
    ans = comb(dic[mi], dic2[mi])
print(tot/A)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

# Combination
MOD = 10**18
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
arr = V[:A]
se = set()
mi = 10**18
dic2 = defaultdict(int)
tot = 0
for a in arr:
    tot += a
    dic2[a] += 1
    se.add(a)
    if a < mi:
        mi = a
dic = defaultdict(int)
for v in V:
    dic[v] += 1
if len(se) == 1:
    ans = 0
    for i in range(1, B+1):
        ans += comb(dic[mi], i)
else:
    ans = comb(dic[mi], dic2[mi])
print(tot/A)
print(ans)

Submission status: Wrong Answer

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

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

total = 0
pattern = 0

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

Submission status: Wrong Answer

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

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

total = 0
pattern = 0

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

Submission status: Wrong Answer

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

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

total = 0
pattern = 0

if len(set(V)) == 1:
  for i in range(1,N):
    c = 1
    for j in range(N,N - i,-1):
      c *= j
    d = [t for t in range(1,i + 1)]
    d = reduce(mul,d)
    c /= d
    pattern += c
  a = A - 1
  print(float(V[0]))
  print(pattern + 1)
else:
  a = A - 1
  sect = V[:A]
  total += sum(sect) / A
  print(total)
  c = V[a]
  dup = sect.count(c)
  print(C[c] - dup + 1)

Submission status: Wrong Answer

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

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

total = 0
pattern = 0

if len(set(V)) == 1:
  for i in range(1,N):
    c = 1
    for j in range(N,N - i,-1):
      c *= j
    d = [t for t in range(1,i + 1)]
    d = reduce(mul,d)
    c /= d
    pattern += c
  a = A - 1
  print(V[0])
  print(pattern + 1)
else:
  a = A - 1
  sect = V[:A]
  total += sum(sect) / A
  print(total)
  c = V[a]
  dup = sect.count(c)
  print(C[c] - dup + 1)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
vlist=list(map(int,input().split()))
#vlist.sort(reverse=True)

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

for i in range(1,N+1):
  dp[i][0]=(0,1)
  for j in range(1,i+1):
    dp[i][j]=dp[i-1][j]
    if dp[i-1][j-1][0]+vlist[i-1]>dp[i][j][0]:
      dp[i][j]=(dp[i-1][j-1][0]+vlist[i-1],dp[i-1][j-1][1])
    elif dp[i-1][j-1][0]+vlist[i-1]==dp[i][j][0]:
      dp[i][j]=(dp[i][j][0],dp[i][j][1]+dp[i-1][j-1][1])
#print(dp)

max_value_avg=0
for j in range(A,B+1):
  #print(j,dp[N][j])
  value_avg=dp[N][j][0]/j
  max_value_avg=max(max_value_avg,value_avg)

answer=0
for j in range(A,B+1):
  value_avg=dp[N][j][0]/j
  if value_avg==max_value_avg:
    answer+=dp[N][j][1]
  
print(answer)

Submission status: Wrong Answer

Solution code:
class cmbs(object):
    def __init__(self, mod=9007199254740997):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 2 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    m = sum(v[:A])/A
    print(m)
    if v.count(v[A-1]) == N:
        c = cmbs()
        a = 0
        for i in range(A, B+1):
            a += c.cmb(N, i)
        print(a)
    elif v[0] == v[A-1]:
        c = cmbs()
        a = 0
        for i in range(A, min(v.count(v[A-1]), B)):
            a += c.cmb(v.count(v[A-1]), i)
        print(a)
    elif v.count(v[A-1]) == 1:
        print(1)
    else:
        c = cmbs()
        r = A - v.index(v[A-1])
        print(c.cmb(v.count(v[A-1]), r))
main()

Submission status: Wrong Answer

Solution code:
class cmbs(object):
    def __init__(self, mod=9007199254740997):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 2 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    m = sum(v[:A])/A
    print(m)
    if v.count(v[A-1]) == N:
        c = cmbs()
        r = 0
        for i in range(A, B+1):
            r += c.cmb(N, i)
        print(r)
    elif v.count(v[A-1]) == 1:
        print(1)
    else:
        c = cmbs()
        r = A - v.index(v[A-1])
        print(c.cmb(v.count(v[A-1]), r))
main()

Submission status: Wrong Answer

Solution code:
class cmbs(object):
    def __init__(self, mod=9007199254740997):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 2 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    m = sum(v[:A])/A
    print(m)
    if v.count(v[A-1]) == N:
        c = cmbs()
        r = 0
        for i in range(A, B+1):
            r += c.cmb(N, i)
        print(r)
    elif v.count(v[A-1]) == 1:
        print(1)
    else:
        c = cmbs()
        r = v.index(v[A-1]) - (A - 1) + 1
        print(c.cmb(v.count(v[A-1]), r))
main()

Submission status: Wrong Answer

Solution code:
import math
def comb(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=1)
tmp=sum(v[:a])
ans=(tmp,a)
x=[a]
for i in range(a+1,b):
    tmp+=v[i]
    if ans[0]*i<=ans[1]*tmp:
        if ans[0]*i==ans[1]*tmp:
            x.append(i)
        else:
            x=[i]
print(ans[0]/ans[1])
ans=0
for i in x:
    a,b=v.count(v[i]),v[i+1:].count(v[i])
    ans+=comb(a,b)
print(ans)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
n, a, b = map(int, input().split())
*V, = map(int, input().split())
D = {}
for v in V:
    try:
        D[v] += 1
    except BaseException:
        D[v] = 1
VC = []
for v, c in zip(D.keys(), D.values()):
    VC.append((v, c))
VC.sort(reverse=True)
V.sort(reverse=True)
s = 0
for v, c in VC[:a]:
    s += v
print(s / a)
x = D[V[a - 1]]
y = a - sum([c for v, c in VC if v > V[a - 1]])
if y == a:
    print(sum([int(comb(x, i, exact=True)) for i in range(a, min(b, x) + 1)]))
else:
    print(int(comb(x, y, exact=True)))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
n, a, b = map(int, input().split())
*V, = map(int, input().split())
D = {}
for v in V:
    try:
        D[v] += 1
    except BaseException:
        D[v] = 1
VC = []
for v, c in zip(D.keys(), D.values()):
    VC.append((v, c))
VC.sort(reverse=True)
V.sort(reverse=True)
s = 0
for v, c in VC[:a]:
    s += v
print(s / a)
x = D[V[a - 1]]
y = a - sum([c for v, c in VC if v > V[a - 1]])
if y == a:
    print(sum([comb(x, i, exact=True) for i in range(a, min(b, x) + 1)]))
else:
    print(comb(x, y, exact=True))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
n, a, b = map(int, input().split())
*V, = map(int, input().split())
D = {}
for v in V:
    try:
        D[v] += 1
    except BaseException:
        D[v] = 1
VC = []
for v, c in zip(D.keys(), D.values()):
    VC.append((v, c))
VC.sort(reverse=True)
s = 0
for v, c in VC[:a]:
    s += v
print(s / a)
x = D[V[a - 1]]
y = a - sum([c for v, c in VC if v > V[a - 1]])
if y == a:
    print(sum([comb(x, i, exact=True) for i in range(a, min(b, x) + 1)]))
else:
    print(comb(x, y, exact=True))

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    v=list(map(int,readline().split()))
    v.sort(reverse=True)

    #average
    average=sum(v[:A])/A

    #combination
    res=0
    x=v[A-1]
    x_count=v.count(x)
    x_count_copy=x_count
    if x==v[0]:
        up=1
        down=1
        for i in range(1,A):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        if x_count>=B:
            for i in range(A,B+1):
                up*=x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
        else:
            for i in range(A,x_count+1):
                up*x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
    else:
        m=A
        for i in range(A):
            if v[i]>x:
                m-=1
            else:
                break
        up=1
        down=1
        for i in range(1,m+1):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        res+=up//down

    print(average)
    print(res)
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

# (合計, 個数)
max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)

res = int(op(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))
elif v[0] == v[B-1]:
    res = 0
    for i in range(A, A+num2+1):
        res += int(op(num1+num2,i))
elif v[0] == v[A-1]:
    res = 0
    for i in range(A, min(B, A+num2)+1):
        res += int(op(num1+num2, i))
print(max_avg[0]/max_avg[1])
print(res)

Submission status: Wrong Answer

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

# (合計, 個数)
max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)

res = int(op(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))
elif v[0] == v[B-1]:
    res = 0
    for i in range(A, A+num2+1):
        res += int(op(num1+num2,i))
elif N!=A and v[0] == v[A-1]:
    res = 0
    for i in range(A, min(B, A+num2)+1):
        res += int(op(num1+num2, i))
print(max_avg[0]/max_avg[1])
print(res)