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: Accepted

Solution code:
INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush

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

def nck(n,k):
    return fac[n]//fac[n - k]//fac[k]

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

    v.sort(reverse=True)
    tot = sum(v[:a])
    cnt = a

    ok = 0
    change = 0
    for i in range(a,n):
        if v[i] * cnt == tot:
            ok += 1
        elif v[i] == v[a - 1]:
            change += 1
    
    same = 1
    for i in range(a - 2,-1,-1):
        if v[i] == v[a - 1]:
            same += 1
    
    ans = 0
    if ok > 0:
        for i in range(same,b - a + same + 1):
            ans += nck(same + ok,i)
    elif change > 0:
        ans += nck(same + change,same)
    else:
        ans += 1

    print(tot/cnt)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial


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

if C[keys[0]] >= A:
    mean = keys[0]
    var = 0
    for i in range(A, min(B, C[keys[0]]) + 1):
        var += factorial(C[keys[0]]) // factorial(i) // factorial(C[keys[0]] - i)
else:
    cnt = 0
    total = 0
    var = 0
    for v in keys:
        if cnt + C[v] < A:
            cnt += C[v]
            total += v * C[v]
        else:
            total += v * (A - cnt)
            mean = total / A
            var += factorial(C[v]) // factorial((A - cnt)) // factorial(C[v] - (A - cnt))
            break

print(mean)
print(var)

Submission status: Accepted

Solution code:
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i + 1] = self.factorial[i] * (i + 1) % mod
        self.inv[n] = pow(self.factorial[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.factorial[m]

    def invfact(self, m):
        return self.inv[m]

    def perm(self, m, k):
        if m < k: return 0
        return self.factorial[m] * self.inv[m - k] % self.mod

    def comb(self, m, k):
        if m < k: return 0
        return self.factorial[m] * self.inv[k] * self.inv[m - k] % self.mod

    def hcomb(self, m, k):
        if m + k == 0: return 1
        return self.comb(m + k - 1, k)


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

V.sort(reverse=True)

F = Factorial(100, 100000000000000000039)

res = 0
num = 1
val = 0

for n in range(A, B + 1):
    v = 0
    for i in range(n):
        v += V[i]
    m = 0
    k = 0
    for i in range(N):
        if V[i] == V[n - 1]:
            m += 1
            if i > n - 1:
                k += 1
    if val * n < v * num:
        res = F.comb(m, k)
        num = n
        val = v
    elif val * n == v * num:
        res += F.comb(m, k)
    else:
        pass

print(val / num)
print(res)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def sml_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 main():
    n, a, b = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort()
    ave = 0
    for i in range(1, a+1):
        ave += v[n-i]
    ave /= a
    l, r = -1, -1
    target = v[n-a]
    for i in range(n):
        if v[i] == target:
            l = i
            break
    for i in reversed(range(n)):
        if v[i] == target:
            r = i
            break
    cnt = r-l+1
    high, low = min(cnt, r-(n-b)+1), r-(n-a)+1
    ans = sml_cmb(cnt, low)
    if v[n-a] == v[n-1]:
        for i in range(low+1, high+1):
            ans += sml_cmb(cnt, i)
    print(ave)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
X.sort(reverse=True)
M = sum(X[i] for i in range(A)) / A
print(M)
cntl, cntr = 0, 0
if X[A-1] == X[N-1]:
  cntr = N - A
else:
  cntr = A-1
  while X[A-1] == X[cntr]:
    cntr += 1
  cntr -= A
if X[0] == X[A-1]:
  cntl = A
else:
  cntl = A-1
  while X[A-1] == X[cntl]:
    cntl -= 1
  cntl = A - 1 - cntl
F = 0
c = cntl + cntr
if cntl == A:
  t = 1
  for m in range(A):
    t *= c - m
    t //= m + 1
  for m in range(A, min(B, c)+1):
    F += t
    t *= c - m
    t //= m + 1
  print(F)
else:
  # calc comb(cntl + cntr, cntl)
  t = 1
  for m in range(cntl):
    t *= c - m
    t //= m + 1
  F = t
  print(F)

Submission status: Accepted

Solution code:
from collections import Counter
import math
def nCr(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

values = [int(i) for i in input().split()]
values.sort(reverse=True)

MAX = sum(values[:a]) / a
print(MAX)
e = a + 1
use_nums = []
for i in range(a, b + 1):
    v = sum(values[:i]) / i
    if v == MAX:
        use_nums.append(Counter(values[:i]))

cd = Counter(values)
ans = 0
for nums in use_nums:
    t = 1
    for k, v in nums.items():
        m = cd.get(k)
        t = t * nCr(m, v)
    ans += t
print(ans)

Submission status: Accepted

Solution code:
from math import factorial
def comb(n,r):
  if n-r<0:
    return 0
  return factorial(n)//(factorial(r)*factorial(n-r))
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
mod=10**9+7
v.sort(reverse=True)
x=v[a-1]
cnt=0
s=0
for i in range(n):
  if x==v[i]:
    cnt+=1
  if x<v[i]:
    s=i+1
ans=0
print(sum(v[:a])/a)
if v[0]==v[a-1]:
  for i in range(a,min(cnt+1,b+1)):
    ans+=comb(cnt,i)
  print(ans)
else:
  ans=comb(cnt,a-s)
  print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
su=sum(v[:a])
avg=su/a
tot=0
inside=0
c=[ [0]*51 for _ in range(51)]
for i in range(n+1):
    for j in range(i+1):
        if j==0 or j==i:
            c[i][j]=1
        else:
            c[i][j]=c[i-1][j]+c[i-1][j-1]
for i in range(n):
    if v[i]==v[a-1]:
        tot+=1
        if i<a:
            inside+=1
cnt=0
if inside==a:
    for i in range(a,b+1):
        cnt+=c[tot][i]
else:
    cnt+=c[tot][inside]
print(avg)
print(cnt)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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

dp=[[[-1,0] for j in range(n+1)] for i in range(n+1)]

dp[0][0]=[0,1]
# print(dp)
for i in range(n):
    for j in range(n):
        if dp[i][j][0]==-1:
            continue
        if dp[i][j][0]==dp[i+1][j][0]:
            dp[i+1][j][1]+=dp[i][j][1]

        if dp[i][j][0]>dp[i+1][j][0]:
            dp[i+1][j]=dp[i][j][:]
        
        if dp[i][j][0]+v[i]==dp[i+1][j+1][0]:
            dp[i+1][j+1][1]+=dp[i][j][1]
        
        if dp[i][j][0]+v[i]>dp[i+1][j+1][0]:
            dp[i+1][j+1][0]=dp[i][j][0]+v[i]
            dp[i+1][j+1][1]=dp[i][j][1]
# print(dp)
ans=0
for i in range(a,b+1):
    ans=max(ans, dp[-1][i][0]/i)
print(ans)
cnt=0
for i in range(a,b+1):
    if ans==dp[-1][i][0]/i:
        cnt+=dp[-1][i][1]
print(cnt)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

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

ans = 0
for i in range(A,B+1):
    ans = max(sum(v[:i])/i, ans)

cnt = 0
for i in range(A,B+1):
    if sum(v[:i])/i == ans:
        n = v.count(v[i-1])
        r = i-v.index(v[i-1])
        cnt += math.factorial(n)//math.factorial(r)//math.factorial(n-r)

print(ans)
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

def combination(n, k):
    numer = denom = 1
    for i in range(k):
        numer = numer * (n-i)
        denom = denom * (i+1)
    return numer // denom

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
ave = sum(v[N-A:]) / A
x = v[N-A]
comb = 0
if x == v[-1]:
    n = N - bisect_left(v, x)
    for k in range(A, min(B, n)+1):
        comb += combination(n, k)
else:
    n = bisect_right(v, x) - bisect_left(v, x)
    k = bisect_right(v, x) - (N - A)
    comb = combination(n, k)
print(ave)
print(comb)

Submission status: Accepted

Solution code:
import math
        
def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
            
import collections  
    
n,a,b = map(int,input().split())

t = list(map(int,input().split()))

c = collections.Counter(t)

c = sorted(c.items(), key=lambda x:-x[0])

memo = 0

for k,i in enumerate(c):
    #print(k,i[0],i[1])
    memo += i[1]
    if a<=memo:
        ans = 0
        memo2 = 0
        for j in range(k+1):
            if j != k:
                memo2 += c[j][1]
                ans += c[j][0]*c[j][1]
            else:
                ans += c[j][0]*(a-memo2)
        print(ans/a)
        break
if c[0][1] <= a:  
    print(combination(c[j][1],a-memo2))
else:
    ans1=0
    for l in range(a,min(c[0][1],b)+1):
        ans1 += combination(c[j][1],l)
    print(ans1)

Submission status: Accepted

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,A,B= (int(x) for x in input().split())
v = list(map(int, input().strip().split()))
v.sort(reverse=True)
print(sum(v[0:A])/A)
ctall = 0
ct = 0
for i in range (A):
    if v[i] == v[A-1]:
        ct += 1
answer = 0
for i in range (N):
    if v[i] == v[A-1]:
        ctall += 1
    if v[i] < v[A-1]:
        break
if (ct == A):
    for i in range(A,min(ctall+1,B+1)):
        answer += combinations_count(ctall, i)
    print(answer)
else: print(combinations_count(ctall, ct))

Submission status: Accepted

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

v.sort(reverse=True)

mx=-1
for i in range(a,b+1):
    mx = max(mx,sum(v[:i])/i)
print(mx)

def modinv(a, mod=10**24+7):
    return pow(a, mod-2, mod)

def comb(n, r, mod=10**24+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

import collections
c = collections.Counter(v)
ans=0
for i in range(a,b+1):
    if sum(v[:i])/i == mx:
        cnt=1

        c2 = collections.Counter(v[:i])

        for itm in c2.items():
            base_cnt = c[itm[0]]
            cnt*=comb(base_cnt,itm[1])
        ans+=cnt

print(ans)

Submission status: Accepted

Solution code:
def ncr(n,r):
    g = 1
    for i in range(1,r+1):
        g*=(n-r+i)
        g//=i
    return g
n,a,b= map(int,input().split())
nv = sorted(list(map(int,input().split())),reverse=True)
print(sum(nv[:a])/a)
ndica = {}
ndicfull = {}
conti = 0
fnv=nv[0]
for i,temp in enumerate(nv):
    if i<a:ndica[temp] = ndica.get(temp,0) + 1
    ndicfull[temp] = ndicfull.get(temp,0) + 1
    if temp==fnv:conti=i+1
if fnv == nv[a-1]:
    subb = min(conti,b)
    g=0
    for t in range(a,subb+1):g+=ncr(conti,t)
    print(g)
else:
    if ndicfull[nv[a-1]]==1:print(1)
    else:print(ncr(ndicfull[nv[a-1]],ndica[nv[a-1]]))

Submission status: Accepted

Solution code:
from math import factorial as f

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

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

v.sort(reverse=True)

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

ans = 0
cnt0 = v.count(v[0])

if cnt0 >= a:
  for i in range(a, min(cnt0, b)+1):
    ans += comb(cnt0, i)
else:
  c = v[a-1]
  cnt1 = 0
  cnt2 = 0
  for i, vi in enumerate(v):
    if vi != c:
      continue
    if i < a:
      cnt1 += 1
    cnt2 += 1
  ans = comb(cnt2, cnt1)

print(ans)

Submission status: Accepted

Solution code:
import math
N,A,B=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
dic={}
for i in range(N):
  v=a[i]
  if v not in dic.keys():
    dic[v]=1
  else:
    dic[v]+=1
tmp=0
num_used={}
m=10**18
M=-1
for i in range(A):
  v=a[i]
  m=min(m,v)
  M=max(M,v)
  tmp+=v
  if v not in num_used.keys():
    num_used[v]=1
  else:
    num_used[v]+=1
max_ave=tmp/A
print(max_ave)
if num_used[m]==dic[m]:
  print(1)
elif m==M:
  x=dic[m]
  y=num_used[m]
  cnt=0
  for i in range(y,min(x+1,B-A+y+1)):
    cnt+=math.factorial(x)//math.factorial(i)//math.factorial(x-i)
  print(cnt)
else:
  x=dic[m]
  y=num_used[m]
  cnt=math.factorial(x)//math.factorial(y)//math.factorial(x-y)
  print(cnt)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
v = inl()
v.sort(reverse=True)
ave = sum(v[:a])/a
print(ave)
if v[0]>v[a-1]:
    l = a-1
    while l>0 and v[l-1]==v[a-1]:
        l -= 1
    r = a-1
    while r<n-1 and v[r+1]==v[a-1]:
        r += 1
    dend = sor = 1
    #ddprint(f"a {a} l {l} r {r}")
    # comb(r-l+1, a-l)
    for i in range(a-l):
        dend *= r-l+1-i
        sor *= a-l-i
    p = dend//sor
    #ddprint(f"i {i} dend {dend} sor {sor} inc {dend//sor} p {p}")
else:
    r = a-1
    while r<n-1 and v[r+1]==v[a-1]:
        r += 1
    # c=min(b,r+1), sum< j=a..c >[comb(r+1,j)]
    p = 0
    #ddprint(f"a {a} l {l} r {r}")
    for j in range(a,min(b,r+1)+1):
        dend = sor = 1
        for i in range(j):
            dend *= r+1-i
            sor *= j-i
        p += dend//sor
        #ddprint(f"i {i} dend {dend} sor {sor} inc {dend//sor} p {p}")
print(p)

Submission status: Accepted

Solution code:
from math import factorial

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

v.sort(reverse = True)

ans = sum(v[:a]) / a
ans2 = 0

count1 = v.count(v[a-1])

index1 = v.index(v[a-1])

def ncr(x,y):
    return factorial(x) // factorial(y) // factorial(x-y)

if v[0] == v[a-1]:
    for i in range(a, min(b, count1) + 1):
        ans2 += ncr(count1, i)
else:
    ans2 = ncr(count1, a - index1)

print(ans)
print(ans2)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=1)
s=sum(v[:A])
print(s/A)
from math import factorial
t=v[A-1]
p,q=0,0
for i in v:
    if i>t:
        p+=1
    elif i==t:
        q+=1
a=0
def c(n,k):
    return (factorial(n)//factorial(k)//factorial(n-k))
for i in range(A,B+1):
    if p+q>=i:
        a+=c(q,i-p)
    if t!=v[0]:
        break
print(a)

Submission status: Accepted

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

count = {}
for x in v:
    if x in count:
        count[x] += 1
    else:
        count[x] = 1

fact = [1] * 51
for i in range(1, 51):
    fact[i] = fact[i-1] * i

def comb(a, b):
    return fact[a] // fact[a-b] // fact[b]

ans = 0
if v[0] == v[a-1]:
    b = min(b, count[v[0]])
    for i in range(a, b+1):
        ans += comb(count[v[0]], i)
    print(v[0])
    print(ans)
else:
    c = v[:a].count(v[a-1])
    print(sum(v[:a]) / a)
    print(comb(count[v[a-1]], c))

Submission status: Accepted

Solution code:
N, A,B,*V = map(int,open(0).read().split())
V = sorted(V)[::-1]
ans1 = sum(V[:A])/A
print(ans1)
f = [1] *51
for i in range(1,51):
  f[i] = f[i - 1] * i
def comb(n,r):
  return f[n]//f[r]//f[n-r]
ans2 = comb(V.count(V[A-1]),V[:A].count(V[A-1]))
if V[0] == V[A-1]:
  for i in range(A+1,B+1):
    ans2 += comb(V.count(V[A-1]),i)
print(ans2)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque, Counter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

fac = [-1] * (10**2+1)

fac[0] = fac[1] = 1

def initNCM(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i

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

initNCM(100)

def main():
    N, A, B = LI()
    v = sorted(LI())[::-1]
    cnt = Counter(v)
    selected = v[:A]
    print(sum(selected)/A)
    ans = 1
    used = 0
    for x in list(set(selected)):
        used += cnt[x]
    used -= cnt[selected[-1]]
    ans = 0
    if len(list(set(selected))) > 1:
        use_last = A - used
        ans += NCM(cnt[selected[-1]], use_last)
    else:
        for use_last in range(1, N+1):
            if not A <= used + use_last <= B:
                continue
            if use_last > cnt[selected[-1]]:
                continue
            ans += NCM(cnt[selected[-1]], use_last)
    print(int(ans))

main()

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
v=[int(x)for x in input().split()]
v.sort(reverse=True)
a=sum(v[:A])/A
m=min(v[:A])
k=v.count(m)
l=v.index(m)
ans=0
import math
for i in range(A,B+1):
    if i==A:
        ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
    else:
        if k-i+l>=0 and a==m:
            ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
        else:
            break
            
            
print("{:.6f}".format(a))
print(int(ans))

Submission status: Accepted

Solution code:
import math
from collections import Counter

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

v.sort(reverse = True)
cnt_v = Counter(v)
ave = []

for i in range(A, B+1):
    ave.append(sum(v[0:i]) / i)

max_ave = max(ave)
ans = 0

for j in range(B-A+1):
    temp = 1
    if ave[j] == max_ave:
        l = v[:A+j]
        cnt_l = Counter(l)
        for key, values in cnt_l.items():
            temp *= (math.factorial(cnt_v[key]) // math.factorial(values) // math.factorial(cnt_v[key] - values))
        ans += temp

print(max_ave)
print(ans)

Submission status: Accepted

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

from itertools import accumulate
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=1)
va = v[:A]
maxa = sum(va)/A
maxsum = sum(va)
print(maxa)
count = 1
if va[0] == va[-1]:
    v0 = va[0]
    v0c = v.count(v0)
    ans = comb(v0c,A)
    for i in range(A,B):
        if v[i] == v0:
            ans += comb(v0c,i+1)
    print(ans)
else:
    v1 = va[-1]
    v1c = va.count(v1)
    v1c2 = v.count(v1)
    print(comb(v1c2,v1c))

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,A,B=MI()
    v=LI()
    v.sort(reverse =True)
    a=0#確定分
    b=0#選ぶ選択肢の個数
    L=[]#個数のリスト
    cnt=1
    temp=v[0]
    for i in range(1,N):
        if v[i]!=temp:
            L.append(cnt)
            cnt=1
            temp=v[i]
        else:
            cnt+=1
            
            
    L.append(cnt)
        
    cnt2=0    
    for i in range(len(L)):
        a=cnt2
        cnt2+=L[i]
        if cnt2>A:
            b=L[i]
            break
    temp1=0
    if a!=0:
        temp1=sum(v[:a])/a
    ans1=sum(v[:A])/A
    if a==A:
        b=0
      
    
    def cmb(n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        temp=1
        for i in range(r):
            temp*=(n-i)
            
        for i in range(r):
            temp=temp//(i+1)
            
        return temp
        
        
    ans2=0
    if temp1>ans1:
        ans2=cmb(b,A-a)
    else:
        for i in range(A-a,B-a+1):
            ans2+=cmb(b,i)
        
    print(ans1)
    print(ans2)

main()

Submission status: Accepted

Solution code:
from collections import Counter


def binomial_coefficient(n, r):
    res = 1
    for i in range(r):
        res *= (n - i)
        res //= (i + 1)
    return res


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

C = Counter(V)

ave = sum(V[:A]) / A
num = V[A - 1]
Nnums = C[num]

if num == V[0]:
    B = min(B, Nnums)
    cnt = 0
    for i in range(A, B + 1):
        cnt += binomial_coefficient(Nnums, i)
else:
    for k, v in C.items():
        if k > num:
            A -= v
    cnt = binomial_coefficient(Nnums, A)

print(ave)
print(cnt)

Submission status: Accepted

Solution code:
def comb(n, r):
    if n < r:
        return 0

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

    return ret


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

v.sort(reverse=True)
ave = sum(v[:a]) / a

if v[0] == v[a-1]:
    sm = v.count(v[0])
    cnt = 0
    for i in range(a, b + 1):
        cnt += comb(sm, i)

else:
    last = v[a-1]
    select = v[:a].count(last)
    sm = v.count(last)
    cnt = comb(sm, select)

print(ave)
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def comb(n: int, r: int):
    if r > n - r:
        return comb(n, n - r)
    p = q = 1
    for i in range(r):
        p *= n - i
        q *= i + 1
    return p // q


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort(reverse=True)
    sl = v[:A]
    print(sum(sl) / A)
    if len(set(sl)) == 1:
        m = sl[0]
        cm = v.count(m)
        ans = 0
        for z in range(A, min(cm, B) + 1):
            ans += comb(cm, z)
        print(ans)
    else:
        m = sl[-1]
        cm = v.count(m)
        print(comb(cm, sl.count(m)))


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#mAx average set
n,a,b=map(int,input().split())
lists=list(map(int,input().split()))
lists=sorted(lists)
P=sum(lists[-a:])
print(P/a)
#Bことって総和がminiになっている
from collections import Counter
J=dict(Counter(lists))
K=dict(Counter(lists[-a:]))
import math
ans=1
sums=0
if J[max(lists)]<a:
    for some in K.keys():
        ans*=(math.factorial(J[some])//((math.factorial(K[some]))*math.factorial(J[some]-K[some])))
    print(ans)
elif J[max(lists)]>a:
    for i in range(a,min(b,J[max(lists)])+1):
        sums+=math.factorial(J[max(lists)])//(math.factorial(J[max(lists)]-i)*math.factorial(i))
    print(sums)
else:
    print(1)

Submission status: Accepted

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

def main():
    N,A,B = map(int,input().split())
    v = sorted(list(map(int,input().split())),reverse=True)
    use = v[:A]
    print(sum(use)/A)
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)

    x = v.count(v[A-1])
    y = use.count(use[A-1])
    
    if v[0] == v[A-1]:
        ans = 0
        for i in range(A,min(B,x)+1):
            ans += fac[x]//(fac[i]*fac[x-i])
        print(ans)
    else:
        ans = fac[x]//(fac[y]*fac[x-y])
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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 = (A-1) - v.index(target) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    #print((n, fromk))
    ans = comb(n, fromk)
    print(ans)

Submission status: Accepted

Solution code:
from math import factorial as f
def comb(n, k):
  return f(n)//f(k)//f(n-k)

n, a, b = map(int, input().split())
V = sorted(map(int, input().split()))
s = sum(V[-a:]) / a
print(s)
small = V[-a]
cnt = V[-a:].count(small)
total = V.count(small)
if V[-1] != small:
  ans = comb(total, cnt)
else:
  ans = 0
  for i in range(a, min(b, total)+1):
    ans += comb(total, i)
print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
d = [[0] * (n + 1) for _ in range(n + 1)]
d[0][0] = 1
for i in range(n):
    for j in range(i + 1):
        if dp[i + 1][j] < dp[i][j]:
            d[i + 1][j] = d[i][j]
            dp[i + 1][j] = dp[i][j]
        elif dp[i + 1][j] == dp[i][j]:
            d[i + 1][j] += d[i][j]
        if dp[i + 1][j + 1] < dp[i][j] + v[i]:
            d[i + 1][j + 1] = d[i][j]
            dp[i + 1][j + 1] = dp[i][j] + v[i]
        elif dp[i + 1][j + 1] == dp[i][j] + v[i]:
            d[i + 1][j + 1] += d[i][j]
ans = 0
idx = float('inf')
cnt = 0
for i in range(a, b + 1):
    if dp[n][i] * idx > ans * i:
        ans = dp[n][i]
        idx = i
        cnt = d[n][i]
    elif dp[n][i] * idx == ans * i:
        cnt += d[n][i]
print(ans / idx)
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort()
N=50
bikkuri=[1 for i in range(N+1)]
for i in range(N):
    bikkuri[i+1]=(i+1)*bikkuri[i]
def comb(a,b):
    if b==0:
        return 1
    else:
        return bikkuri[a]//(bikkuri[a-b]*bikkuri[b])
ans1=0
ans2=0
if V[-a]==V[-1]:
    ans1=V[-1]
    VC=Counter(V)
    num=VC[ans1]
    for i in range(a,min(b,num)+1):
        ans2+=comb(num,i)
else:
    ans1=sum(V[-a:])/a
    A=list(set(V[-a:]))
    VC=Counter(V)
    num1=VC[V[-a]]
    VaC=Counter(V[-a:])
    num2=VaC[V[-a]]
    ans2=comb(num1,num2)
print(ans1)
print(ans2)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from math import factorial

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
V = np.array(lr())
V.sort()
if A == 1:
    ave = V[-A]
else:
    ave = V[-A:].sum() / A
print(ave)
left_i = np.searchsorted(V, V[-A], side='left')
right_i = np.searchsorted(V, V[-A], side='right')
num = right_i - left_i
done = N - right_i

bottom = A-done
top = B-done

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

answer = combinations_count(num, bottom)
if ave == V[-A] and num > 1:
    for i in range(bottom+1, min(num, top)+1):
        answer += combinations_count(num, i)

print(answer)
# 15

Submission status: Accepted

Solution code:
kai = [1]

s = 1
for i in range(1,51):
    s *= i
    kai.append(s)

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

vl = list(map(int,input().split()))
vl = sorted(vl)
member = vl[-a:]
ans = sum(vl[-a:]) / len(vl[-a:])
v = vl[-a]
m = vl.count(v)
k = member.count(v)
if member[0] == member[-1]:
    print(ans)
    ans2 = 0
    for i in range(a, min(b, m)+1):
        ans2 += kai[m] // (kai[i] * kai[m-i])
    print(ans2)

else:
    print(ans)
    print(kai[m]//(kai[k] * kai[m-k]))

Submission status: Accepted

Solution code:
from collections import Counter

from scipy.misc import comb
#a = comb(n, r, exact=True)

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

V.sort(reverse = True)
C = Counter(V)

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

max_value = V[0]

# V[0], ... V[A-1] がすべて同じとき、そうでないときで異なる
# V[0], ... V[A-1] に異なるものが含まれると、Aコ選ぶときがMAX
key_value = V[A-1]
if key_value < max_value:
  # V[A-1]の個数と、その前に何個あるかを数えればよい
  forward_item_count = 0
  for k,v in C.items():
    if k > key_value:
      forward_item_count += v

  print(int(comb(C[key_value], A - forward_item_count, exact=True)))
  exit(0)
  
# すべて同じときはAコ～Bコ選んでも平均一緒。組み合わせ数を足していく必要性
ans = 0
cnts = C[key_value]
for i in range(A,B+1):
  ans += comb(cnts,i, exact=True)
  
print(int(ans))

Submission status: Accepted

Solution code:
def factorial(num):
    if num==0 or num==1:
        return 1
    else:
        return num*factorial(num-1)

N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
maxsum=0
for i in range(0,A):
    maxsum+=v[N-1-i]
maxaverage=((maxsum*(10**6))//A)/(10**6)

s=v[N-A]
count1=0
count2=0
for i in range(0,A):
    if v[N-1-i]==s:
        count1+=1
for i in range(0,N):
    if v[i]==s:
        count2+=1
if count1!=A:
    way=factorial(count2)//(factorial(count1)*factorial(count2-count1))
    print(maxaverage)
    print(way)
else:
    way=0
    for i in range(A,min(count2,B)+1):
        way+=factorial(count2)//(factorial(i)*factorial(count2-i))
    print(maxaverage)
    print(way)