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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial
from collections import defaultdict


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 = [int(x) for x in input().split()]
goods.sort()
goods.reverse()

counter = defaultdict(int)
for v in goods:
    counter[v] += 1

avg, nums = 0, []
for x in range(a, b + 1):
    if sum(goods[:x]) / x == avg:
        nums.append(x)
        continue

    if sum(goods[:x]) / x > avg:
        avg = sum(goods[:x]) / x
        nums = [x]

print(avg)

total = 0
for num in nums:
    c = 0
    for x in sorted(counter.keys()):
        c += counter[x]
        if c == num:
            total += 1
            break

        if c > num:
            total += comb(counter[x], counter[x] - (c - num))
            break

print(total)

Submission status: Wrong Answer

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

from math import factorial
from collections import defaultdict


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 = [int(x) for x in input().split()]
goods.sort()
goods.reverse()

counter = defaultdict(int)
for v in goods:
    counter[v] += 1

avg, num = 0, 0
for x in range(a, b + 1):
    if sum(goods[:x]) / x >= avg:
        avg = sum(goods[:x]) / x
        num = x

print(avg)

c = 0
for x in sorted(counter.keys()):
    c += counter[x]
    if c > num:
        print(comb(counter[x], counter[x] - (c - num)))
        break

Submission status: Wrong Answer

Solution code:
import operator as op
from functools import reduce


def ncr(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    if r == 0:
        return 1
    numer = reduce(op.mul, range(n, n - r, -1))
    denom = reduce(op.mul, range(1, r + 1))
    return numer // denom

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


print(sum(v[0:a]) / a)
res = 0
if v[0] == v[-1]:
    for i in range(a, b + 1):
        res += ncr(n, i)
else:
    cnt = v.count(v[a - 1])
    res = ncr(cnt, v[0:a].count(v[a - 1]))
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from statistics import mean
from math import factorial


def product(n, r):
    """return nPr"""
    from math import factorial
    return factorial(n) / factorial(n-r)


def combine(n, r):
    """return nCr"""
    from math import factorial
    return factorial(n) / factorial(r) / factorial(n-r)

N, A, B = [int(n) for n in input().split()]
v = sorted([int(n) for n in input().split()], reverse = True)

max_mean = mean(v[0:A])
selected_min = v[A-1]
X = A
Y = A
for i, v_ in enumerate(v[:A]):
    if v_ == v[A-1]:
        X = i + 1
        break

for i, v_ in enumerate(v[A:]):
    if v_ == v[A-1]:
        Y = A + i + 1

if v[0] != v[A-1]:
    val = combine(Y-X+1, A-X+1)
else:
    val = 0
    for i in range(A, min(B, Y)+1):
        val += combine(Y, i)

print(max_mean)
print(int(val))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from statistics import mean
from math import factorial


def product(n, r):
    """return nPr"""
    from math import factorial
    return factorial(n) / factorial(n-r)


def combine(n, r):
    """return nCr"""
    from math import factorial
    return factorial(n) / factorial(r) / factorial(n-r)

N, A, B = [int(n) for n in input().split()]
v = sorted([int(n) for n in input().split()], reverse = True)

max_mean = mean(v[0:A])
selected_min = v[A-1]
X = A
Y = A
for i, v_ in enumerate(v[:A]):
    if v_ == v[A-1]:
        X = i + 1
        break

for i, v_ in enumerate(v[A:]):
    if v_ == v[A-1]:
        Y = A + i + 1

if v[0] != v[A-1]:
    val = combine(Y-X+1, A-X+1)
else:
    val = 0
    if Y > B:
        M = B
    else:
        M = Y
    for i in range(A, M+1):
        val += combine(Y, i)

print(max_mean)
print(int(val))

Submission status: Wrong Answer

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 i in chk[::-1]:
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

#n=int(input())
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(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 i in chk[::-1]:
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

#n=int(input())
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(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 i in chk[::-1]:
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]

Submission status: Wrong Answer

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

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

retv=v[:A]
print '{:.6f}'.format(sum(retv)/(A*1.0))

dupcnt=v[:A].count(v[A-1])
for i in xrange(B-A):
    if v[A]==v[A+i]:
        dupcnt+=1
r=0
for i in xrange(dupcnt):
    r+=nCr(dupcnt,i)
print r

Submission status: Wrong Answer

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

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

retv=v[:A]
print sum(retv)/(A*1.0)

dupcnt=v[:A].count(v[A-1])
for i in xrange(B-A):
    if v[A]==v[A+i]:
        dupcnt+=1
r=0
for i in xrange(dupcnt):
    r+=nCr(dupcnt,i)
print r

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

n, a, b = map(int, raw_input().split())
l = map(int, raw_input().split())

l.sort(reverse = True)
s = 0

for i in range(a):
	s += l[i]

s = float(s) / a
print s

q = l[i]
c, d = 0, 0

for i in range(n):
	if (i < a) and (l[i] == q):
		c += 1
	if (i >= a) and (l[i] == q):
		d += 1

e = c + d

if q < s:
	print int(comb(e, c))
else:
	ss = 0
	for i in range(a, b + 1):
		ss += comb(e, i)
	print int(ss)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

n, a, b = map(int, raw_input().split())
l = map(int, raw_input().split())

l.sort(reverse = True)
s = 0

for i in range(a):
	s += l[i]

s = float(s) / a
print s

q = l[i]
c, d = 0, 0

for i in range(n):
	if (i < a) and (l[i] == q):
		c += 1
	if (i >= a) and (l[i] == q):
		d += 1

e = c + d

if q < s:
	print int(comb(e, c))
else:
	ss = 0
	for i in range(a, b + 1):
		ss += int(comb(e, i))
	print ss

Submission status: Wrong Answer

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

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

retv=v[:A]
print sum(retv)/(A*1.0)

dupcnt=1
for i in xrange(B-A):
    if v[A]==v[A+i]:
        dupcnt+=1
r=0
for i in xrange(dupcnt):
    r+=nCr(dupcnt,i)
print r

Submission status: Wrong Answer

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

v.sort()
v = v[::-1]
ave = []
ko = []

for i in range(A, B + 1):
    v_use = v[0:i]
    ko_in = v_use.count(v_use[-1])
    ko_all = v.count(v_use[-1])
    ko.append(math.factorial(ko_all) /
              math.factorial(ko_all - ko_in) / math.factorial(ko_in))
    sum_ = 0
    for j in v_use:
        sum_ += j
    ave.append(float(sum_) / i)
max_ = max(ave)
ans_ind = []
for i in range(B + 1 - A):
    if max_ - ave[i] <= 10**-6:
        ans_ind.append(i)

ans = 0
for i in ans_ind:
    ans += ko[i]

print(max_)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())

v = map(int, raw_input().split())

v.sort()
v.reverse()

resultValue = 0
resultCount = long(0)

for pcs in range(A, B + 1):
    average = float(sum(v[:pcs])) / pcs
    if resultValue < average:
        resultValue = average

for pcs in range(A, B + 1):
    maxAverage = float(sum(v[:pcs])) / pcs
    if maxAverage == resultValue:
        n = v.count(min(v))
        k = pcs
        count = 1
        for i in range(k):
            count *= (n - i)
        for i in range(k):
            count /= (k - i)
        resultCount += count

print(resultValue)
print(resultCount)

Submission status: Wrong Answer

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

v.sort()
v = v[::-1]
ave = []
ko = []

for i in range(A, B + 1):
    v_use = v[0:i]
    ko_in = v_use.count(v_use[-1])
    ko_all = v.count(v_use[-1])
    ko.append(math.factorial(ko_all) /
              math.factorial(ko_all - ko_in) / math.factorial(ko_in))
    sum_ = 0
    for j in v_use:
        sum_ += j
    ave.append(float(sum_) / i)
max_ = max(ave)
ans_ind = []
for i in range(B + 1 - A):
    if max_ - ave[i] < 10**-6:
        ans_ind.append(i)

ans = 0
for i in ans_ind:
    ans += ko[i]

print(max_)
print(int(ans))

Submission status: Wrong Answer

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

v.sort()
v = v[::-1]
ave = []
ko = []

for i in range(A, B + 1):
    v_use = v[0:i]
    ko_in = v_use.count(v_use[-1])
    ko_all = v.count(v_use[-1])
    ko.append(math.factorial(ko_all) /
              math.factorial(ko_all - ko_in) / math.factorial(ko_in))
    sum_ = 0
    for j in v_use:
        sum_ += j
    ave.append(float(sum_) / i)
max_ = max(ave)
ans_ind = []
for i in range(B + 1 - A):
    if max_ - ave[i] < 10**-6:
        ans_ind.append(i)

ans = 0
for i in ans_ind:
    ans += ko[i]

print(int(ans))

Submission status: Wrong Answer

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

v.sort()
v = v[::-1]
ave = []
ko = []

for i in range(A, B + 1):
    v_use = v[0:i]
    ko_in = v_use.count(v_use[-1])
    ko_all = v.count(v_use[-1])
    ko.append(math.factorial(ko_all) /
              math.factorial(ko_all - ko_in) / math.factorial(ko_in))
    sum_ = 0
    for j in v_use:
        sum_ += j
    ave.append(float(sum_) / i)
max_ = max(ave)
ans_ind = []
for i in range(B + 1 - A):
    if max_ - ave[i] < 10**-6:
        ans_ind.append(i)

ans = 0
for i in ans_ind:
    ans += ko[i]

print(ans)

Submission status: Wrong Answer

Solution code:
nab = list(map(int, input().split()))
def fact(n):
    if n <= 1:
        return 1
    else:
        return n * fact(n-1)

def p(n, k):
    n_fact = fact(n)
    n_k_fact = fact(n-k)
    return n_fact / n_k_fact

N = nab[0]
A = nab[1]
B = nab[2]

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

V = sorted(V)

max_averaged_value = sum(V[-A:]) / A

prev_e = -1
cnt = [0 for i in range(N)]
cnt[0] = 0
c = 0
for e in V:
    if prev_e == e:
       cnt[c] += 1
    else:
       c += 1
    prev_e = e

cnt = cnt[:A]
com = 1
for i in cnt[:-1]:
    com *= fact(i)

d = A - sum(cnt[:-1])
com *= p(cnt[-1], d)

print(max_averaged_value)
print(int(com))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from statistics import mean
from math import factorial

N, A, B = [int(n) for n in input().split()]
v = sorted([int(n) for n in input().split()], reverse = True)

max_mean = mean(v[0:A])
selected_min = v[A-1]
X = A
Y = A
for i, v_ in enumerate(v[:A]):
    if v_ == v[A-1]:
        X = i + 1
        break

for i, v_ in enumerate(v[A:]):
    if v_ == v[A-1]:
        Y = A + i + 1

if v[0] != v[A-1]:
    val = factorial(Y - X + 1)/factorial(Y-A)
else:
    val = 0
    if Y > B:
        M = B
    else:
        M = Y
    for i in range(A, M+1):
        val += factorial(Y) / factorial(Y-i+1)

print(max_mean)
print(int(val))

Submission status: Wrong Answer

Solution code:
nab = list(map(int, input().split()))
def fact(n):
    if n <= 1:
        return 1
    else:
        return n * fact(n-1)

def p(n, k):
    n_fact = fact(n)
    n_k_fact = fact(n-k)
    return n_fact / n_k_fact

N = nab[0]
A = nab[1]
B = nab[2]

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

V = sorted(V)

max_averaged_value = sum(V[-A:]) / A

prev_e = -1
cnt = [0 for i in range(N)]
cnt[0] = 0
c = 0
for e in V:
    if prev_e == e:
       cnt[c] += 1
    else:
       c += 1
    prev_e = e

cnt = cnt[:A]
com = 1
for i in cnt[:-1]:
    com *= fact(i)

d = A - sum(cnt[:-1])
print(cnt[-1])
com *= p(cnt[-1], d)

print(max_averaged_value)
print(int(com))

Submission status: Wrong Answer

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

def combination(a, b):
    u, d = 1, 1
    for i in range(b):
        u *= a - i
        d *= b - i
    
    return u // d

s_i = sum(v[:A])
c_i = A
ans = 0
a = A
while s_i * a == sum(v[:a]) * c_i and a <= B:
    last_num = None
    c = 0
    for i in range(a):
        n = v[i]
        if n == last_num:
            c += 1
        else:
            c = 0
        
        last_num = n

    ans += combination(v.count(v[a - 1]), c)
    a += 1

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

Submission status: Wrong Answer

Solution code:
nab = list(map(int, input().split()))
def fact(n):
    if n <= 1:
        return 1
    else:
        return n * fact(n-1)

def p(n, k):
    n_fact = fact(n)
    n_k_fact = fact(n-k)
    return n_fact / n_k_fact

N = nab[0]
A = nab[1]
B = nab[2]

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

V = sorted(V)

max_averaged_value = sum(V[-A:]) / A

prev_e = V[0]
cnt = [1 for i in range(N)]
cnt[0] = 0
c = 0
for e in V:
    if prev_e == e:
       cnt[c] += 1
    else:
       c += 1
    prev_e = e

cnt = cnt[:A]
com = 1
for i in cnt[:-1]:
    com *= fact(i)

d = A - sum(cnt[:-1])
print(cnt[-1])
com *= p(cnt[-1], d)

print(max_averaged_value)
print(int(com))

Submission status: Wrong Answer

Solution code:
import math

def search(a):
    if v[a]==v[a-1] and a-1>=0:
        return search(a-1)
    else:
        return a


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

v.sort()

eq = [0]*N

for i in range(N)[::-1]:
    eq[i] = search(i)

sum = 0
j = N-1
for i in range(A):
    sum += v[j]
    j -= 1

j += 1
m_ave = sum/A


count = 1

flag = A
for i in range(A+1,B+1)[::-1]:
    sum = 0
    for j in range(i,N):
        sum += v[j]
    if sum/i == m_ave:
        flag = i
    else:
        break

for i in range(A,flag+1):
    for k in range(0,i+1):
        if N-k-1 != eq[N-k-1] :
                count+=math.factorial((N-j-1)-(eq[N-j-1]))




print(m_ave)
print(count)

Submission status: Wrong Answer

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

def combination(a, b):
    b = max(b, 1)
    u, d = 1, 1
    for i in range(b):
        u *= a - i
        d *= b - i
    
    return u // d

s_i = sum(v[:A])
c_i = A
ans = 0
a = A
while s_i * a == sum(v[:a]) * c_i and a <= B:
    last_num = None
    c = 0
    for i in range(a):
        n = v[i]
        if n == last_num:
            c += 1
        else:
            c = 0
        
        last_num = n

    ans += combination(v.count(v[a - 1]), c)
    a += 1

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

Submission status: Wrong Answer

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

def combination(a, b):
    b = max(b, 1)
    u, d = 1, 1
    for i in range(b):
        u *= a - i
        d *= b - i
    
    return u // d

s_i = sum(v[:A])
c_i = A
ans = 0
a = A
while s_i / c_i == sum(v[:a]) / a and a <= B:
    last_num = None
    c = 0
    for i in range(a):
        n = v[i]
        if n == last_num:
            c += 1
        else:
            c = 0
        
        last_num = n

    ans += combination(v.count(v[a - 1]), c)
    a += 1

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

Submission status: Wrong Answer

Solution code:
import math

def search(a):
    if v[a]==v[a-1] and a-1>=0:
        return search(a-1)
    else:
        return a


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

v.sort()

eq = [0]*N

for i in range(N)[::-1]:
    eq[i] = search(i)

sum = 0
j = N-1
for i in range(A):
    sum += v[j]
    j -= 1

j += 1
m_ave = sum/A


count = 1

flag = A
for i in range(A+1,B+1)[::-1]:
    sum = 0
    for j in range(i,N):
        sum += v[j]
    if sum/i == m_ave:
        flag = i
    else:
        break

for i in range(A,flag+1):
    print(N-i,eq[N-i])
    if (N-i)-(eq[N-i])>0:
        count+=math.factorial((N-i)-(eq[N-i]))
    else:
        break

print(m_ave)
print(count)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(int, raw_input().split())
V = list(sorted(V))
def Mean(S):
    return float(sum(S))/len(S)

def Factorial(n):
    if n == 1:
        return 1.0
    elif n == 0:
        return 1.0
    else:
        return n*Factorial(n - 1)

def NCR(n, r):
    return int(Factorial(n)/(Factorial(n - r) * Factorial(r)))

ss = []
mm = 0 # max mean
for i in xrange(A, B + 1):
    subset = V[-i:]
    m = Mean(subset)
    if m > mm:
        ss = [subset]
        mm = m
    elif m == mm:
        if subset not in ss:
            ss.append(subset)
print '{0:.06f}'.format(mm)
res = 0
for subset in ss:
    nonredundant = list(set(subset))
    prod = 1
    for j in nonredundant:
        prod *= NCR(V.count(j), subset.count(j))
    res += prod
print res

Submission status: Wrong Answer

Solution code:
import math

def search(a):
    if v[a]==v[a-1] and a-1>=0:
        return search(a-1)
    else:
        return a


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

v.sort()

eq = [0]*N

for i in range(N)[::-1]:
    eq[i] = search(i)

sum = 0
j = N-1
for i in range(A):
    sum += v[j]
    j -= 1

j += 1
m_ave = sum/A


count = 1

flag = A
for i in range(A+1,B+1)[::-1]:
    sum = 0
    for j in range(i,N):
        sum += v[j]
    if sum/i == m_ave:
        flag = i
    else:
        break

for i in range(A,flag+1):
    if (N-i)-(eq[N-i])>0:
        count+=(N-i)-(eq[N-i])
    else:
        break

print(m_ave)
print(count)

Submission status: Wrong Answer

Solution code:
import math

def search(a):
    if v[a]==v[a-1] and a-1>=0:
        return search(a-1)
    else:
        return a


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

v.sort()

eq = [0]*N

for i in range(N)[::-1]:
    eq[i] = search(i)

sum = 0
j = N-1
for i in range(A):
    sum += v[j]
    j -= 1

j += 1
m_ave = sum/A


count = 1

flag = A
for i in range(A+1,B+1)[::-1]:
    sum = 0
    for j in range(i,N):
        sum += v[j]
    if sum/i == m_ave:
        flag = i
    else:
        break

for i in range(A,flag+1):
    if (N-i)-(eq[N-i])>0:
        count+=math.factorial((N-i)-(eq[N-i]))
    else:
        break

print(m_ave)
print(count)

Submission status: Wrong Answer

Solution code:
import math

# def comboSum(n, chooseMin, chooseMax):
# 	print(n, chooseMin, chooseMax)
# 	ways = 0
# 	for i in range(chooseMin, chooseMax + 1):
# 		localWays = math.factorial(n) // math.factorial(i) // math.factorial(n - i)
# 		ways += localWays
# 	return ways


def avg(L, atLeast, atMost):
	if (L.count(max(L)) >= atLeast):
		print(max(L))
		ways = 0
		for i in range(atLeast, L.count(max(L)) + 1):
			localWays = math.factorial(L.count(max(L))) // math.factorial(i) // math.factorial(L.count(max(L)) - i)
			ways += localWays
		print(ways)
		return
	L.sort(reverse=True)
	last = L[atLeast - 1]
	print(sum(L[:atLeast]) / atLeast)
	firstIndex = L.index(last)
	# lastIndex = len(L) - (sorted(L).index(last)) - 1
	n = L.count(last)
	i = atLeast - firstIndex
	print(math.factorial(n) // math.factorial(i) // math.factorial(n - i))

[N, atLeast, atMost] = list(map(lambda x: int(x), input().split()))
L = list(map(lambda x: int(x), input().split()))
avg(L, atLeast, atMost)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

import operator as op

def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

has = defaultdict(int)

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

arr = map(int, raw_input().split())

for i in arr:
    has[i] += 1

arr.sort()
arr.reverse()

tempSum = sum(arr[: a])
mean = float(tempSum)/a

sol = arr[: a]
newMean = mean
for i in xrange(b-a):
    newMean = float(tempSum + arr[a + i])/(a + i + 1)
    if newMean >= mean:
        mean = newMean
        tempSum += arr[a + i]
        sol.append(arr[a + i])
    else:
        break
    
newHas = defaultdict(int)

for i in sol:
    newHas[i] += 1
ans = 1
for i in set(sol):
    ans *= ncr(has[i], newHas[i])
  
if int(mean) == arr[0]:
    ans = 0
    for i in xrange(has[arr[0]]):
        ans += ncr(has[arr[0]], i+1)
  
print '%0.8f' %mean
print ans

Submission status: Wrong Answer

Solution code:
import itertools
 
N, A, B = map(int, raw_input().split())
 
v = map(int, raw_input().split())
 
resultValue = 0
resultCount = 0

for pcs in range(B - A + 1):
    perm = list(itertools.combinations(v, B + pcs))
    for cand in perm:
        average = float(sum(cand)) / len(cand)
        if resultValue < average:
            resultValue = average
            resultCount = 1
        elif resultValue == average:
            resultCount += 1

print(resultValue)
print(resultCount)

Submission status: Wrong Answer

Solution code:
import math

def avg(L, atLeast, atMost):
	if (L.count(max(L)) >= atLeast):
		print(max(L))
		ways = 0
		for i in range(atLeast, L.count(max(L)) + 1):
			localWays = math.factorial(L.count(max(L))) // math.factorial(i) // math.factorial(L.count(max(L)) - i)
			ways += localWays
		print(ways)
		return
	L.sort(reverse=True)
	last = L[atLeast - 1]
	print(sum(L[:atLeast]) / atLeast)
	print(L.count(last))

[N, atLeast, atMost] = list(map(lambda x: int(x), input().split()))
L = list(map(lambda x: int(x), input().split()))
avg(L, atLeast, atMost)

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        max_n_max = max(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(max_n_max) // math.factorial(max_n_max - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= num_cnt // cnt
        print(max_avg_ptn)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

def solve():
    N, A, B = map(int, input().split())
    v = [int(i) for i in input().split()]
    v.sort(reverse=True)

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

    onaji = v.count(v[0])

    if onaji < A:
        k = v[:A].count(v[A - 1])
        n = v.count(v[A - 1])
        cnt = binom(n, k)
    else:
        cnt = 0

        for i in range(A, onaji + 1):
            cnt += binom(onaji, i)

    print('{:.8f}'.format(ave_max))
    print(cnt)


def binom(n, k):
    return (factorial(n) // factorial(n - k)) // factorial(k)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

import operator as op

def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

has = defaultdict(int)

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

arr = map(int, raw_input().split())

for i in arr:
    has[i] += 1

arr.sort()
arr.reverse()

tempSum = sum(arr[: a])
mean = float(tempSum)/a

sol = arr[: a]
newMean = mean
for i in xrange(b-a):
    newMean = float(tempSum + arr[a + i])/(a + i + 1)
    if newMean >= mean:
        mean = newMean
        tempSum += arr[a + i]
        sol.append(arr[a + i])
    else:
        break
    
newHas = defaultdict(int)

for i in sol:
    newHas[i] += 1
ans = 1
for i in set(sol):
    ans *= ncr(has[i], newHas[i])
    
print '%0.8f' %mean
print ans

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(max_n) // math.factorial(max_n - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= num_cnt // cnt
        print(max_avg_ptn)

if __name__ == '__main__':
    main()