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: Runtime Error

Solution code:
import numpy as np
import scipy.special as ss
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = np.array(v)
##print(v)
ansarray = v[0:A]
##print(ansarray)
ave = np.mean(ansarray)
print(ave)
mi = min(ansarray)
ma = max(ansarray)
biggerarray = v[v>mi]
m = len(biggerarray)
numminarray = v[v==mi]
a = len(numminarray)
##print(nummin)
##print(num_kouho)
ans = 0
if ma == mi:
    if m+a <= B:
        for i in range(A-m,a+1):
            ans+=ss.comb(a,i)
    else:
        for i in range(A-m,B-m+1):
            ans+=ss.comb(a,i)

else:
    ans = a
#print('a=',a)
#print('m=',m)
print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
elif cnt == A:
    print(1)
else:
    ans = 0
    for r in range(A,B+1):
        ans += ncr[cnt][r]
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
else:
    ans = 0
    for r in range(A,B+1):
        ans += ncr[cnt][r]
    print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)
revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0
if v[-1] == v[-a] == v[-a-1]:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);
else:
    print(ncr(num,a-revpos));

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)
ans=0
if v[-1] == v[-a] == v[-a-1]:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);

else:
    print(ncr(num,a-revpos));

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)
ans=0
if v[-1] == v[-a] == v[-a-1]:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);

else:
    print(1);

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)

revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0;
if a == revpos:
    print(1);
else:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)

revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0;
if a == revpos:
    print 1;
else:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);

Submission status: Runtime Error

Solution code:
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)

revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0;
for i in range(a-revpos, b-revpos+1):
    ans+=ncr(num, i);
print(ans);

Submission status: Runtime Error

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)

min=v[A]


C=v[0:A].count(min)#最低個数
D=v[0:A].count(min)+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(min)#最小の人たちの個数
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: Runtime Error

Solution code:
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 = imtes[: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: Runtime Error

Solution code:

def f1(i):
  if(i == 1):
    return 1
  return i*f1(i-1)

def f2(a, b):
  print(a, b)
  return f1(a)/(f1(b)*f1(a-b))
a = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

sorted_v = sorted(v)

b = []
c = {}

sum = 0
count = 0
for i in range(a[1]):
  b.append(sorted_v[a[0] - i -1])
  if(not sorted_v[a[0] - i -1] in c):
    c[sorted_v[a[0] - i -1]] = 1
  else:
    c[sorted_v[a[0] - i -1]] += 1
  sum += sorted_v[a[0] - i -1]
  count += 1

pattern = 1
memory = count

max = max(b)

if(max == sorted_v[a[0] - memory -1] and count == c[sorted_v[a[0] - memory -1]] ):
   tmp = c[max]
   while(max == sorted_v[a[0] - memory -1]):
     c[max] += 1
     memory += 1
     if(a[0] - memory -1 == -1):
        break
   if(c[max] > a[2]):
      pattern = 0
      pattern = f2(c[max], a[2])
   else:
      pattern = 1
   for i in range(a[1], min(c[max], a[2])):
     pattern += f2(c[max], i)


else:
    if(sorted_v[a[0] - memory -1] == b[-1]):
      e = c[sorted_v[a[0] - memory -1]]
      while(sorted_v[a[0] - memory -1] == b[-1]):
        c[sorted_v[a[0] - memory -1]] += 1
        memory += 1
        if(a[0] - memory -1 == -1):
          memory -= 1
          break
      pattern = f2(c[sorted_v[a[0] - memory -1]], e)
    else:
      pattern = 1


print("{0:.7f}".format(sum/count))
print(pattern)

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
li = []
for i in range(n):
    li.append(int(input()))
li = sorted(li)
m = sum(li[-a: -1])
print(m)
c = 0
p = 1
for i in range(b - a):
    if li[-a - i] == li[-a]:
        c += 1
for i in li[-a: -1]:
    if i == li[-a]:
        p += c
print(p)

Submission status: Runtime Error

Solution code:
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, max(b, l) + 1)))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

def nCr(n, r):
    return(len(list(itertools.combinations(np.arange(n), p))))

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: Runtime Error

Solution code:
#! coding: UTF-8
data1 = list(map(int,input().split(" ")))
N = data1[0]
A = data1[1]
B = data1[2]
data2 = list(map(int,input().split(" ")))
data2.sort(reverse=True)
max_avr = sum(data2[:A]) / A
a_num = data2.count(data2[A-1])
a_pos = data2[:A].count(data2[A-1])
#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
cnt = 0
if a_pos == A:
    while a_pos <= B:
        cnt += nCr(a_num,a_pos)
        a_pos += 1
else:
    cnt = nCr(a_num,a_pos)
print("{0:.10f}".format(max_avr))
print(int(cnt))

Submission status: Runtime Error

Solution code:
#! coding: UTF-8
data1 = list(map(int,input().split(" ")))
N = data1[0]
A = data1[1]
B = data1[2]
data2 = list(map(int,input().split(" ")))
data2.sort(reverse=True)
max_avr = sum(data2[:A]) / A
a_num = data2.count(data2[A-1])
a_pos = data2[:A].count(data2[A-1])
#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
cnt = 0
if a_pos == A:
    while a_pos <= B:
        cnt += nCr(a_num,a_pos)
        a_pos += 1
else:
    cnt = nCr(a_num,a_pos)
print("{0:.6f}".format(max_avr))
print(int(cnt))

Submission status: Runtime Error

Solution code:
#! coding: UTF-8
data1 = list(map(int,input().split(" ")))
N = data1[0]
A = data1[1]
B = data1[2]
data2 = list(map(int,input().split(" ")))
data2.sort(reverse=True)
max_avr = sum(data2[:A]) / A
a_num = 0
a_pos = 0
for i in range(N):
	if data2[i] == data2[A-1]:
		a_num += 1
		if i < A:
			a_pos += 1
#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
cnt = 0
if a_pos == A:
    while a_pos <= B:
        cnt += nCr(a_num,a_pos)
        a_pos += 1
else:
    cnt = nCr(a_num,a_pos)
print("{0:.6f}".format(max_avr))
print(int(cnt))

Submission status: Runtime Error

Solution code:
#! coding: UTF-8
data1 = list(map(int,input().split(" ")))
N = data1[0]
A = data1[1]
B = data1[2]
data2 = list(map(int,input().split(" ")))
data2.sort(reverse=True)
max_avr = sum(data2[:A])
max_avr /= A
a_num = 0
a_pos = 0
for i in range(N):
	if data2[i] == data2[A-1]:
		a_num += 1
		if i < A:
			a_pos += 1
#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
cnt = 0
if a_pos == A:
    while a_pos <= B:
        cnt += nCr(a_num,a_pos)
        a_pos += 1
else:
    cnt += nCr(a_num,a_pos)
print("{0:.6f}".format(max_avr))
print(int(cnt))

Submission status: Runtime Error

Solution code:
#! coding: UTF-8
data1 = list(map(int,input().split(" ")))
N = data1[0]
A = data1[1]
B = data1[2]
data2 = list(map(int,input().split(" ")))
data2.sort(reverse=True)
max_avr = 0
for i in range(A):
	max_avr += data2[i]
max_avr /= A
a_num = 0
a_pos = 0
for i in range(N):
	if data2[i] == data2[A-1]:
		a_num += 1
		if i < A:
			a_pos += 1
#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
cnt = 0
if a_pos == A:
    while a_pos <= B:
        cnt += nCr(a_num,a_pos)
        a_pos += 1
else:
    cnt += nCr(a_num,a_pos)
print("{0:.6f}".format(max_avr))
print(int(cnt))