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:
import math

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

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

mini=v[A]
C=v[0:A].count(mini)#最低個数
D=v[0:A].count(mini)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(mini)#最小の人たちの個数
D=min(D,p)

q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))

Submission status: Accepted

Solution code:
# ARC59 D input
nab = list(map(int, input().split()))

N = nab[0]
A = nab[1]
B = nab[2]
V = list(reversed(sorted(list(map(int, input().split())))))

# ARC59 D naive
def count(n):
    result = []
    prev = V[0]
    count = 1
    for i, v in enumerate(V[1:n]):
        if (v == prev):
            count += 1
        else:
            result.append(count)
            count = 1
        
        if(i == n-2):
            result.append(count)
        prev = v
        
    return result
        
def greedy(n):
    return sum(V[0:n])/n

def fact(n):
    res = 1
    for i in range(1,n+1):
        res *= i
    return res

def comb(p, u):
    nume = 1
    for i in range(u):
        nume *= (p-i)
    return int(nume / fact(u))


max_ave = -1
max_ave_comb = 0
counts = count(N)

for i in range(A, B+1):
    u = i # u is the number of items to pick
    ave = greedy(i)
    if (max_ave <= ave):
        for j in counts:
            if (u-j <= 0):
                if (max_ave != ave):
                    max_ave_comb = comb(j, u)
                else:
                    max_ave_comb += comb(j, u)
                break
            else:
                u -= j
        max_ave = ave
print(max_ave)
print(max_ave_comb)

Submission status: Accepted

Solution code:
import numpy as np
def comb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a-i)
    for i in range(b):
        ans /= (i+1)
    return ans
N, A, B = map(int, raw_input().split())
v = sorted(map(np.int64, raw_input().split()))
value_num_mapping = {}
for _ in v:
    if not _ in value_num_mapping:
        value_num_mapping[_] = 0
    value_num_mapping[_] += 1

best = np.mean(v[-A:])
ans = 0
for T in range(A, B+1):
    if np.sum(v[-T:]) * A== np.sum(v[-A:]) * T:
        cnt = len([_ for _ in v[-T:] if _ == v[-T]])
        ans += comb(value_num_mapping[v[-T]], cnt)
print best
print ans

Submission status: Accepted

Solution code:
import math

def comb(n, m) :
    fact = math.factorial
    return fact(n) // fact(m) // fact(n-m)

N, A, B = map(int, input().split())
val = list(reversed(sorted(map(int, input().split()))))

ret = 0
prev = [0, 1]
for i in range(A, B + 1):
    cur = [sum([val[j] for j in range(i)]), i]
    if i > A and prev[0] * cur[1] > prev[1] * cur[0]:
        break
    ret += comb(val.count(val[i-1]), val[:i].count(val[i-1]))
    prev = cur

print(format(prev[0] / prev[1], '.12f'))
print(ret)

Submission status: Accepted

Solution code:
from builtins import print


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


N, A, B = map(int, input().split())
val = list(reversed(sorted((map(int, input().split())))))

ret = 0

prev = [0, 1]
for i in range(A, B+1) :
    cur = [ sum( [ val[j] for j in range(i) ]) , i]
    if i > A :
        if prev[0] * cur[1] > prev[1] * cur[0] :
            break
    cntLarge = [ 1 if v > val[A] else 0 for v in val  ].count(1)
    ret += comb( val.count(val[i-1]) ,i - cntLarge)
    prev = cur

print(format(prev[0] / prev[1], '.12f'))
print(ret)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize



def combi(n, r):
  if r == 0 or n == r:
    return 1
  return combi(n-1, r-1) + combi(n-1, r)

n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list)/len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
  print(1)
elif max_ave_list[0] != max_ave_list[-1]:
  print(combi(l, m))
else:
  print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

Submission status: Accepted

Solution code:
n, a, b = map(int, raw_input().split())
V = sorted(map(int, raw_input().split()))
C = {}
for v in V:
    C[v] = C.get(v, 0) + 1

memo = {}
def comb(n, k):
    if n == k or k == 0:
        return 1
    if (n, k) in memo:
        return memo[n, k]
    res = memo[n, k] = comb(n-1, k) + comb(n-1, k-1)
    return res

su = 0.
count = 0

cur = 0
tmp = 0.
for k in sorted(C.keys(), reverse=True):
    if cur >= b:
        break
    if cur+C[k] < a:
        cur += C[k]
        tmp += C[k]*k
    else:
        for c in xrange(max(a, cur+1), min(b, cur+C[k])+1):
            tmp_ = tmp + k*(c-cur)
            if su*c < tmp_:
                su = tmp_/c
                count = comb(C[k], c-cur)
            elif su*c == tmp_:
                count += comb(C[k], c-cur)
        cur += C[k]
        tmp += C[k]*k
print "%.6f" % su
print count

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize
def combi(n, r):
    if r == 0 or n == r:
        return 1
    return combi(n - 1, r - 1) + combi(n - 1, r)


n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list) / len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
    print(1)
elif max_ave_list[0] != max_ave_list[-1]:
    print(combi(l, m))
else:
    print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

Submission status: Accepted

Solution code:
def ncr(n, r):
  res = 1
  for k in range(r):
    res *= n - k
    res //= k + 1
  return res
 
(n, a, b) = [int(x) for x in input().split(' ')]
v = [int(x) for x in input().split(' ')]
v.sort(reverse=True)
 
su = 0
avg = 0
for x in v[:a]:
  su += x
avg = su / a
 
comb = 0
cnt1 = v.count(v[a - 1])
cnt2 = v[:a].count(v[a - 1])
if v[0] == v[a - 1]:
  for i, vi in enumerate(v[a - 1:b]):
    if vi == v[a - 1]:
      comb += ncr(cnt1, cnt2 + i)
else:
  comb = ncr(cnt1, cnt2)

print(avg)
print(comb)

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()

def average(l,a):
    sum=0
    for i in range(a):
        sum+=l[i]
    return (sum/a)


kaijoulist=[1,1]
def kaijou(n):
    t=len(kaijoulist)
    while t<=n:
        kaijoulist.append(kaijoulist[-1]*t)
        t+=1
    return kaijoulist[n]

def combination(n,k):
    return int(kaijou(n)/(kaijou(k)*kaijou(n-k)))



max_index=[A]
max=average(v,A)
for i in range(A+1,B+1):
    ave=average(v,i)
    if max<ave:
        max_index=[i]
        max=ave
    elif max==ave:
        max_index.append(i)

li_uniq = list(set(max_index))



answer=0
for i in li_uniq:
    x=v[i-1]
    kosuu=v.count(x)
    sentou=v.index(x)
    answer+=combination(kosuu,i-sentou)

print(max)
print(answer)

Submission status: Accepted

Solution code:
#! coding: UTF-8
N,A,B = list(map(int,input().split(" ")))
V = list(map(int,input().split(" ")))
V.sort(reverse=True)
max_avr = sum(V[:A]) / A
a_num = V.count(V[A-1])
a_pos = V[:A].count(V[A-1])

#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

if V[0] == V[A-1]:
    cnt = sum(nCr(a_num,i) for i in range(A,min(B,a_num)+1)) 
else:
    cnt = nCr(a_num,a_pos)
print("{0:.10f}".format(max_avr))
print(int(cnt))

Submission status: Accepted

Solution code:
import numpy as np

N, A, B = list(map(int, input().split()))
V = np.array(list(map(int, input().split())))
V.sort()
V[:] = V[::-1]

def fac(n):
    return 1 if n<=1 else n*fac(n-1)
        
def nCr(n, r):
    return fac(n) // fac(n-r) // fac(r)

d = V[A-1]
# unless all equal, we only need A
if d == V.max():
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    res = nCr(d_eq_cnt, A)
    res_sum = res
    for k in range(1, min(B, d_eq_cnt) + 1 - A):
        res = res * (d_eq_cnt - (A+k-1)) // (A+k)
        res_sum += res
    print(V[:A].mean())
    print(res_sum)
    
    
else:
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    d_lq_cnt = np.count_nonzero(V > d)
    print(V[:A].mean())
    print(nCr(d_eq_cnt, A - d_lq_cnt))

Submission status: Accepted

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

num = [0 for x in range(N)]
total = [0 for x in range(N)]

for i, v in enumerate(L):
    for j in reversed(range(1, i + 1)):
        new_v = total[j - 1] + v
        if(new_v > total[j]):
            total[j] = new_v
            num[j] = num[j - 1]
        elif(new_v == total[j]):
            num[j] = num[j] + num[j - 1]

    if(v > total[0]):
        total[0] = v
        num[0] = 1
    elif(v == total[0]):
        num[0] = num[0] + 1

total = [x / (i + 1) for i, x in enumerate(total)]
total = total[(A - 1):B]
num = num[(A - 1):B]

maxV = max(total)
maxNum = sum([j for i, j in zip(total, num) if i == maxV])
print(maxV)
print(maxNum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

def combinations(n, r):
    res = 1
    for i in xrange(n - r + 1, n + 1):
        res *= i
    for i in xrange(2, r + 1):
        res /= i
    return res

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())
v.sort(reverse = True)
cnt = Counter(v)

mx = sum(v[:A]) 
comb = 0
for n in xrange(A, B + 1):
    tmp = 1
    for key, val in Counter(v[:n]).items():
        tmp *= combinations(cnt[key], val)

    if A*sum(v[:n]) == n*mx:
        comb += tmp 

print "%.10f" % (mx*1.0/A)
print comb

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections

def combinations(n, r):
    res = 1
    for i in xrange(n - r + 1, n + 1):
        res *= i
    for i in xrange(2, r + 1):
        res /= i
    return res

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())
v.sort(reverse = True)

cnt = collections.Counter(v)

mx = sum(v[:A]) 
comb = 0
for n in xrange(A, B + 1):

    tmp_cnt = collections.Counter(v[:n])
    tmp = 1
    for key, val in tmp_cnt.items():
        tmp *= combinations(cnt[key], val)

    if A*sum(v[:n]) == n*mx:
        comb += tmp 

print "%.10f" % (mx*1.0/A)
print comb

Submission status: Accepted

Solution code:
import math

def C(n, r):
	fact = math.factorial
	return fact(n) // fact(r) // fact(n-r)

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

v_sort = sorted(v, reverse=True)

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

a, b = v_sort.count(v_sort[A-1]), v_sort[:A].count(v_sort[A-1])

if v_sort[0] == v_sort[A-1]:
	print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
else:
	print(C(a, b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math


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

# 上からA個
subset = values[-A:]
mean = sum(subset) / len(subset)
print(mean)

def pascals_triangle(n_rows):
    results = []
    for _ in range(n_rows):
        row = [1]
        if results:
            last_row = results[-1]
            row.extend([sum(pair) for pair in zip(last_row, last_row[1:])])
            row.append(1)
        results.append(row)
    return results[-1] # 最後だけでOK

if subset[0] == subset[-1]:
    # 数を増やしてもmeanが減らない可能性がある
    cnt = values.count(subset[0])
    tri = pascals_triangle(cnt + 1)

    if cnt >= B:
        tri_subset = tri[A:B+1]
        print(sum(tri_subset))

    # B > cntなので、
    else:
        tri_subset = tri[A:cnt + 1]
        print(sum(tri_subset))

else:
    # 数を増やすのはあり得ない
    v = subset[0]
    cnt_in_all = values.count(v)
    cnt_in_subset = subset.count(v)

    #ans = combination(cnt_in_all, cnt_in_subset)
    tri = pascals_triangle(cnt_in_all + 1)
    ans = tri[cnt_in_subset]
    print(ans)

Submission status: Accepted

Solution code:
import collections

# Iterative Algorithm (xgcd)
def iterative_egcd(a, b):
    x,y, u,v = 0,1, 1,0
    while a != 0:
        q,r = b//a,b%a; m,n = x-u*q,y-v*q # use x//y for floor "floor division"
        b,a, x,y, u,v = a,r, u,v, m,n
    return b, x, y
 
# Recursive Algorithm
def recursive_egcd(a, b):
    """Returns a triple (g, x, y), such that ax + by = g = gcd(a,b).
       Assumes a, b >= 0, and that at least one of them is > 0.
       Bounds on output values: |x|, |y| <= max(a, b)."""
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = recursive_egcd(b % a, a)
        return (g, x - (b // a) * y, y)
 
egcd = iterative_egcd  # or recursive_egcd(a, m)
 
def modinv(a, m):
    g, x, y = egcd(a, m) 
    if g != 1:
        return None
    else:
        return x % m
 
def conv(n,a):
    ret = 1
    for i in range(1,a+1):
        ret *= n-a+i
        ret //= i
    return ret
        
n,a,b = map(int, input().split(' '))
v = map(int, input().split(' '))

v = sorted(v, reverse=True)
select = v[:a]
result1 = sum(select)/len(select)

result2 = 0
v_cnt = collections.Counter(v)
for i in range(a,b+1):
    select = v[:i]
    if result1 == sum(select)/len(select):
        select = collections.Counter(select)
        buf = 1
        for v_ in v_cnt:
            buf *= conv(v_cnt[v_],select[v_])
        result2 += buf
print('%.6f'%result1)
print(result2)

Submission status: Accepted

Solution code:
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    # use list.sort() or sorted(list)
    v.sort(reverse=True)
    # use slice to sum first A elements
    # use '{:f}'.format to format float
    print('{:.6f}'.format((sum(v[:A]) / A)))

    va = v[A - 1]
    # use list.count instead of (sum(list(map(lambda x: 1 if ... else 0, v))))
    pool = v.count(va)
    # ...and for comprehension and boolean sum
    head = sum(x > va for x in v)
    # 5 4 3 3 3 2 1, A = 3, B = 5, pool = 3, pick = 1
    # 5 4 3 3 3 2 1, A = 4, B = 5, pool = 3, pick = 2
    # 3 3 3 3 3 2 1, A = 3, B = 6, pool = 5, pick = 3, 4, 5
    # 3 3 3 3 3 2 1, A = 3, B = 4, pool = 5, pick = 3, 4
    if head == 0:
        # for comprehension again, instead of a for loop that modifies variable
        ans = sum([_nCr(pool, pick) for pick in range(A, min(B, pool) + 1)])
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    # reduce and xrange are for python2
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = list(reversed(sorted(v)))
    # use slice to sum first A elements
    v_sum = sum(v[:A])
    # use '{:f}'.format to format float
    print('{:.6f}'.format((v_sum / A)))

    pool = sum(list(map(lambda x: 1 if x == v[A] else 0, v)))
    head = sum(list(map(lambda x: 1 if x > v[A] else 0, v[:A])))
    # 5 4 3 3 3 2 1, A = 3, B = 5, pool = 3, pick = 1
    # 5 4 3 3 3 2 1, A = 4, B = 5, pool = 3, pick = 2
    # 3 3 3 3 3 2 1, A = 3, B = 6, pool = 5, pick = 3, 4, 5
    # 3 3 3 3 3 2 1, A = 3, B = 4, pool = 5, pick = 3, 4
    ans = 0
    if head == 0:
        for pick in range(A, min(B, pool) + 1):
            ans += _nCr(pool, pick)
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    # reduce and xrange are for python2
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math


def C(n,r):
    fact = math.factorial
    return fact(n) // fact(r) // fact(n-r)

def main():
    N, A, B = tuple(map(int, input().split(' ')))
    v = list(map(int, input().split(' ')))

    v.sort(reverse=True)

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

    a, b = v.count(v[A-1]), v[:A].count(v[A-1])

    if v[0] == v[A-1]:
        print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
    else:
        print(C(a, b))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import collections


def main():
    #infile = open("compprog.txt")
    #n, a, b = [int(x) for x in infile.readline().split()]
    #nums = [int(x) for x in infile.readline().split()]
    n, a, b = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)
    hml = how_many_largest(nums)
    if hml <= a:
        hml_less(n, a, b, nums, hml)
    elif a < hml < b:
        hml_between(n, a, b, nums, hml)
    else:
        hml_between(n, a, b, nums, b)
    #infile.close()


def hml_less(n, a, b, nums, hml):
    highest = []
    for idx in range(a):
        highest.append(nums[idx])
    mean = sum(highest) / len(highest)
    in_cnt = dict(collections.Counter(highest))
    full_cnt = dict(collections.Counter(nums))
    ways = num_combs(full_cnt[highest[-1]], in_cnt[highest[-1]])
    print(mean)
    print(ways)


def hml_between(n, a, b, nums, hml):
    print(float(nums[0])) # mean
    cnt = dict(collections.Counter(nums))[nums[0]]
    ways = 0
    for i in range(hml, a - 1, -1):
        ways += num_combs(cnt, i)
    print(ways)


def how_many_largest(lst):
    res = 1
    idx = 1
    while idx < len(lst) and lst[idx - 1] == lst[idx]:
        res += 1
        idx += 1
    return res


def num_combs(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    d = sum(v[:A]) / A
    L = [v[:A]]
    for i in range(A+1, B+1):
        if sum(v[:i]) / i == d : L += [v[:i]]
    ans = 0
    for i in L:
        a = 1
        for j in set(i):
            if i.count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i.count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(d)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import factorial

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

C = [[0 for i in range(51)] for j in range(51)] #C[n][k] => nCk

for i in range(51):
    for j in range(i+1):
        if (j == 0 or j == i):
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1] + C[i-1][j]

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = C[X][Y]

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += C[X][i]

print float(sum(v[0:A]))/A
print ans

Submission status: Accepted

Solution code:
import math
 
def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

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

v.sort(reverse=True)

m_ave = sum(v[:A])/A
x,y = v.count(v[A-1]),v[:A].count(v[A-1])

if v[0]==v[A-1] :
    comb = sum([C(x,i) for i in range(A,min(B,x)+1)])
else :
    comb = C (x,y)

print(m_ave)
print(comb)

Submission status: Accepted

Solution code:
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[i-1] == min(S): # reverseしてるからこの[i-1]が決定打
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    
else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Accepted

Solution code:
import math
 
# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d
 
# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
 
# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort()

 
# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[-A:]
ave = sum(S) / A
print(ave)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
    C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
    print(C)
else:
    i = A
    C = 0
    while i <= B and V[-i] == min(S):
        c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
        C = C + c
        i = i + 1
    print(C)

Submission status: Accepted

Solution code:
# 元ソースコード：http://abc057.contest.atcoder.jp/submissions/1183710
# 初心者の実験用です

import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
S = V[-A:]
avgmax = sum(S) / A
print(avgmax)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
	C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
	print(C)
else:
	i = A
	C = 0
	while i <= B and V[-i] == min(S):
		c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
		C = C + c
		i = i + 1
	print(C)

Submission status: Accepted

Solution code:
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

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

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print float(sum(v[0:A]))/A
print ans

Submission status: Accepted

Solution code:
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

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

v.sort(reverse = True)

print float(sum(v[0:A]))/A

X, Y = 0, 0
ans = 0

for i in range(N):
    if (v[i] == v[A-1]):
        X += 1
    if (v[i] == v[A-1]) and (i < A):
        Y += 1

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print ans

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
maxavg = sum(V[:A])/A
print(maxavg)
min = V[A-1]
ltAnum = 0
minnum = 0
for i in range(N):
    if V[i] > min:
        ltAnum = ltAnum + 1
    elif V[i] == min:
        minnum = minnum + 1
    else:
        break
#print(ltAnum)
#print(minnum)

import math
def nCr(n,r):
    f = math.factorial
    return f(n)//f(r)//f(n-r)

c_min = 0
import itertools
if ltAnum > 0:
    c_min = nCr(minnum, A-ltAnum)
if ltAnum == 0:
    for j in range(A, B+1):
        if minnum < j:
            break
        else:
            c_min = c_min + nCr(minnum, j)
print(c_min)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
INF=10**10
from collections import Counter
import scipy.misc as scm

def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

def main():
    N,A,B=list(map(int,input().split()))
    v=list(map(int,input().split()))
    cnt=Counter(v)
    ary=[]
    first=True
    
    for num,count in sorted(cnt.items(),reverse=True):
        if count>A:
            if first:
                a2=0
                print("{:.6f}".format(float(num)))
                for k in range(A,min(B,count)+1):
                    a2+=ncr(count,k)
                print(a2)
                return 0
            
            ary+=[num]*A
            print("{:.6f}".format(sum(ary)/len(ary)))
            print(ncr(count,A))
            return 0
        elif A==0:
            print("{:.6f}".format(sum(ary)/len(ary)))
            print(1)
        else:
            ary+=[num]*count
            A-=count
        first=False
    
        
      
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,a,b=map(int,raw_input().split())
v=[int(i) for i in raw_input().split()]
chk=[i for i in set(v)]
chk.sort()
if len(chk)==1:
    print chk[0]*1.0
    print sum(pscl(n)[a:b+1])
    exit()
d={}
for i in v:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
total=ans=tmp=0
t=a
for p,i in enumerate(chk[::-1]):
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    elif p==0 and d[i]>=t:
        print i*1.0
        print sum(pscl(d[i])[a:min(b,d[i])+1])
        break
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]
        break

Submission status: Accepted

Solution code:
# coding: utf-8
import math

num_N, num_A, num_B = map(int, input().split())
l_val = list(map(int, input().split()))

l_val.sort(reverse=True)

num_cen = l_val[num_A - 1]

count_all = 0
for i in l_val:
    if num_cen == i:
        count_all += 1

count_front = 0
for i in l_val[0:num_A - 1]:
    if i == num_cen:
        count_front += 1

count_back = count_all - count_front - 1

ans = 0

if l_val[0] == num_cen:
    if count_back <= num_B - num_A:
        for i in range(num_A, num_A + count_back + 1):
            ans += math.factorial(count_all) // (math.factorial(count_all - i) * math.factorial(i))
    else:
        for i in range(num_A, num_B + 1):
            ans += math.factorial(count_all) // (math.factorial(count_all - i) * math.factorial(i))
else:
    ans = math.factorial(count_all) // (math.factorial(count_all - (count_front + 1)) * math.factorial(count_front + 1))

print((sum(l_val[0:num_A])) / num_A)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a - 1, b):
        if goods[a - 1] != goods[i]: break
        total += comb(lastcount, i + 1)

print("{}\n{}".format(avg, total))

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = [[sum(v[:A]) / A, v[:A]]]
    for i in range(A+1, B+1):
        if sum(v[:i]) / i == L[0][0] : L += [[sum(v[:i]) / i, v[:i]]]
    ans = 0
    for i in L:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(L[0][0])
    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(reverse=True)

max_average = sum(v[:A]) / A

C = [[0]*51 for i in range(51)]
for i in range(N+1):
    for j in range(i+1):
        if j == 0 or i == 0:
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1] + C[i-1][j]

ans = 0
cnt = 0
if v[0] == v[A-1]:
    for i in range(N):
        if v[i] == v[0]:
            cnt += 1
    for i in range(A, B+1):
        ans += C[cnt][i]
else:
    included = 0
    for i in range(N):
        if v[i] == v[A-1]:
            cnt += 1
            if i < A:
                included += 1
    ans += C[cnt][included]

print(max_average)
print(ans)

Submission status: Accepted

Solution code:
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = sum(v[:a])*1.0/a
print '{0:.6f}'.format(res1)
res2 = 0
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
if a==v[:a].count(v[a-1]):
    res2 = 0
    for i in range(a,b+1):
        if i <= v.count(v[a-1]):
            res2 += nCr(v.count(v[a-1]),i)
    print res2
else:
    print nCr(v.count(v[a-1]),v[:a].count(v[a-1]))