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:
# -*- 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)

# bug in big number
def combination(n, m):
    # n C m
    answer = n
    for i in range(m-1):
        answer *= (n - 1 - i)
    for i in range(1, m + 1):
        answer /= i
    return int(answer)


# bug in big number
def combination2(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))


def pascals_triangle(n_rows):
    results = [] # a container to collect the rows
    for _ in range(n_rows):
        row = [1] # a starter 1 in the row
        if results: # then we're in the second row or beyond
            last_row = results[-1] # reference the previous row
            # this is the complicated part, it relies on the fact that zip
            # stops at the shortest iterable, so for the second row, we have
            # nothing in this list comprension, but the third row sums 1 and 1
            # and the fourth row sums in pairs. It's a sliding window.
            row.extend([sum(pair) for pair in zip(last_row, last_row[1:])])
            # finally append the final 1 to the outside
            row.append(1)
        results.append(row) # add the row to the results.
    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))
    else:
        tri_subset = tri[A:cnt + 1]
        print(sum(tri_subset))
    """
    all = 0
    if cnt >= B:
        for i in range(A, B + 1):
            all += combination(cnt, i)
    else:
        for i in range(A, cnt + 1):
            all += combination(cnt, i)
    print(all)
    """
else:
    # 数を増やすのはあり得ない
    v = subset[0]
    cnt_in_all = values.count(v)
    cnt_in_subset = subset.count(v)
    ans = combination(cnt_in_all, cnt_in_subset)
    print(ans)

Submission status: Wrong Answer

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)

# bug in big number
def combination(n, m):
    # n C m
    answer = n
    for i in range(m-1):
        answer *= (n - 1 - i)
    for i in range(1, m + 1):
        answer /= i
    return int(answer)


def pascals_triangle(n_rows):
    results = [] # a container to collect the rows
    for _ in range(n_rows):
        row = [1] # a starter 1 in the row
        if results: # then we're in the second row or beyond
            last_row = results[-1] # reference the previous row
            # this is the complicated part, it relies on the fact that zip
            # stops at the shortest iterable, so for the second row, we have
            # nothing in this list comprension, but the third row sums 1 and 1
            # and the fourth row sums in pairs. It's a sliding window.
            row.extend([sum(pair) for pair in zip(last_row, last_row[1:])])
            # finally append the final 1 to the outside
            row.append(1)
        results.append(row) # add the row to the results.
    return results[-1] # 最後だけでOK


# bug in big number
def combination2(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))


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


    """
    all = 0
    if cnt >= B:
        for i in range(A, B + 1):
            all += combination(cnt, i)
    else:
        for i in range(A, cnt + 1):
            all += combination(cnt, i)
    print(all)
    """
else:
    # 数を増やすのはあり得ない
    v = subset[0]
    cnt_in_all = values.count(v)
    cnt_in_subset = subset.count(v)
    ans = combination(cnt_in_all, cnt_in_subset)
    print(ans)

Submission status: Wrong Answer

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(' '))
n,a,b = 50,1,50
v = [1]*50

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: Wrong Answer

Solution code:
import collections
from scipy.misc import comb

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 *= comb(v_cnt[v_],select[v_])
        result2 += buf
print('%.6f'%result1)
print(int(round(result2)))

Submission status: Wrong Answer

Solution code:
import collections
from scipy.misc import comb

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 *= comb(v_cnt[v_],select[v_])
        result2 += buf
print('%.6f'%result1)
print(int(result2))

Submission status: Wrong Answer

Solution code:
import collections
from scipy.misc import comb

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 *= comb(v_cnt[v_],select[v_])
        result2 += buf
print(result1)
print(int(result2))

Submission status: Wrong Answer

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)
    print(pool, head)
    # 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: Wrong Answer

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 combination(n, m):
    # n C m
    answer = n
    for i in range(m-1):
        answer *= (n - 1 - i)
    for i in range(1, m + 1):
        answer /= i
    return int(answer)




if subset[0] == subset[-1]:
    # 数を増やしてもmeanが減らない可能性がある
    cnt = values.count(subset[0])
    all = 0
    if cnt >= B:
        for i in range(A, B + 1):
            all += combination(cnt, i)
    else:
        for i in range(A, cnt + 1):
            all += combination(cnt, i)
    print(all)
else:
    # 数を増やすのはあり得ない
    v = subset[0]
    cnt_in_all = values.count(v)
    cnt_in_subset = subset.count(v)
    ans = combination(cnt_in_all, cnt_in_subset)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,A,B = map(int,raw_input().split())
v = map(int,raw_input().split())
#print N,A,B,v
v = np.sort(v)[::-1]
#print np.mean(v[:A])
#print v
max = 0
count = 1
for i in range(B-A+1):
    if max < np.mean(v[:A+i]):
        max = np.mean(v[:A+i])
    elif max == np.mean(v[:A+i]):
        count +=1
print max
#print np.where(v == v[A-1])
print len(np.where(v==v[A-1])[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
N,A,B = map(int,raw_input().split())
v = map(int,raw_input().split())
#print N,A,B,v
v = np.sort(v)[::-1]
#print np.mean(v[:A])
#print v
max = 0
count = 1
for i in range(B-A+1):
    if max < np.mean(v[:A+i]):
        max = np.mean(v[:A+i])
    elif max == np.mean(v[:A+i]):
        count +=1
print max
print count

Submission status: Wrong Answer

Solution code:
import statistics as stats
from math import factorial


def nCr(n, r):
    return int(factorial(n)/factorial(n-r)/factorial(r))


def main():
    N, A, B = tuple(map(int, input().split(' ')))
    max_ave = 0
    v_list = sorted(list(map(int, input().split(' '))), reverse=True)

    bucket_min = v_list[A-1]
    max_ = v_list[0]

    max_bucket = v_list[:A]

    max_ave = stats.mean(max_bucket)

    all_bmin_cnt = v_list.count(bucket_min)
    b_bmin_cnt = max_bucket.count(bucket_min)
    all_max_cnt = v_list.count(max_)

    print(max_ave)

    if A == 1:
        print(2**min(all_max_cnt, B)-1)
    elif all_max_cnt <= A:
        print(nCr(all_bmin_cnt, b_bmin_cnt))
    else:
        num = 0
        for r in range(A, min(all_max_cnt, B)+1):
            print(all_max_cnt, r)
            num += nCr(all_max_cnt, r)
        print(num)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import statistics as stats
from math import factorial


def nCr(n, r):
    return int(factorial(n)/factorial(n-r)/factorial(r))


def main():
    N, A, B = tuple(map(int, input().split(' ')))
    max_ave = 0
    v_list = sorted(list(map(int, input().split(' '))), reverse=True)

    bucket_min = v_list[A-1]
    max_ = v_list[0]

    max_bucket = v_list[:A]

    max_ave = stats.mean(max_bucket)

    all_bmin_cnt = v_list.count(bucket_min)
    b_bmin_cnt = max_bucket.count(bucket_min)
    all_max_cnt = v_list.count(max_)

    print(max_ave)

    if all_max_cnt <= A:
        print(nCr(all_bmin_cnt, b_bmin_cnt))
    elif A < all_max_cnt < B:
        num = 0
        for i in range(A, all_max_cnt+1):
            num += nCr(all_max_cnt, i)
        print(num)
    else:
        print(2**B-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import statistics as stats
from math import factorial


def nCr(n, r):
    return int(factorial(n)/factorial(n-r)/factorial(r))


def main():
    N, A, B = tuple(map(int, input().split(' ')))
    max_ave = 0
    v_list = sorted(list(map(int, input().split(' '))), reverse=True)

    bucket_min = v_list[A-1]
    bucket_max = v_list[0]
    max_bucket = v_list[:A]

    max_ave = stats.mean(max_bucket)

    all_num = v_list.count(bucket_min)
    bucket_num = max_bucket.count(bucket_min)


    print(max_ave)
    if bucket_min == bucket_max and all_num > A:
        print(2**(B-A+1)-1)
    else:
        print(nCr(all_num, bucket_num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import statistics as stats
from math import factorial


def nCr(n, r):
    return int(factorial(n)/factorial(n-r)/factorial(r))


def main():
    N, A, B = tuple(map(int, input().split(' ')))
    max_ave = 0
    v_list = sorted(list(map(int, input().split(' '))), reverse=True)

    bucket_min = v_list[A-1]
    max_bucket = v_list[:A]

    max_ave = stats.mean(max_bucket)

    all_num = v_list.count(bucket_min)
    bucket_num = max_bucket.count(bucket_min)


    print(max_ave)
    if N == all_num:
        print(2**(B)-1)
    else:
        print(nCr(all_num, bucket_num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)
    else:
        hml = b if hml > b else hml
        hml_between(n, a, b, nums, hml)
    #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, 0, -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: Wrong Answer

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)
    else:
        hml = b if hml > b else hml
        hml_between(n, a, b, nums, hml)
    #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(nums[0]) # mean
    cnt = dict(collections.Counter(nums))[nums[0]]
    ways = 0
    for i in range(hml, 0, -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: Wrong Answer

Solution code:
import collections


def main():
    #infile = open("compprog.txt")
    n, a, b = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)
    highest = []
    for idx in range(a):
        highest.append(nums[idx])
    mean = sum(highest) / len(highest)
    idx = a
    while idx < len(nums) and nums[idx] == highest[-1]:
        highest.append(nums[idx])
        idx += 1
    cnt = dict(collections.Counter(highest))
    ways = 1
    for val in cnt.values():
        ways *= val
    print(mean)
    print(ways)
    #infile.close()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n, a, b = [int(i) for i in input().split(" ")]
v = [int(i) for i in input().split(" ")]
v.sort(reverse=True)

res = sum(v[:a])/a
print("{0:.6f}".format(res))

if not v[0]==v[a-1]:
    x = v[:a].count(v[a-1])
    y = v.count(v[a-1])
    print(int(math.factorial(y)/math.factorial(x)/math.factorial(y-x)))
else:
    comb = 0
    for i in range(a, b+1):
        comb += math.factorial(n)/math.factorial(i)/math.factorial(n-i)
    print(int(comb))

Submission status: Wrong Answer

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, X+1):
        ans += comb(X, i)

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

Submission status: Wrong Answer

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)
c_min = math.factorial(minnum)/(math.factorial(minnum-A+ltAnum)*math.factorial(A-ltAnum))
print(int(c_min))

Submission status: Wrong Answer

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(B):
    if V[i] > min:
        ltAnum = ltAnum + 1
    elif V[i] == min:
        minnum = minnum + 1
    else:
        break
c_min = math.factorial(minnum)/(math.factorial(minnum-A+ltAnum)*math.factorial(A-ltAnum))
print(int(c_min))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
maxavg = sum(V[:A])/A
print(maxavg)
print("1")

Submission status: Wrong Answer

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: Wrong Answer

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

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+=scm.comb(count,k)
                print(int(a2))
                return 0
            
            ary+=[num]*A
            print("{:.6f}".format(sum(ary)/len(ary)))
            print(int(scm.comb(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: Wrong Answer

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

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(num)
                for k in range(A,min(B,count)+1):
                    a2+=scm.comb(count,k)
                print(int(a2))
                return 0
            
            ary+=[num]*A
            print(sum(ary)/len(ary))
            print(int(scm.comb(count,A)))
            return 0
        elif A==0:
            print(sum(ary)/len(ary))
            print(1)
        else:
            ary+=[num]*count
            A-=count
        first=False
    
        
      
if __name__=="__main__":
    main()

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

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

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 d,t,d[i],b-(a-t),pscl(d[i])
        #print sum(pscl(d[i])[t:min(d[i],b-(a-t))+[0,1][d[i]>b-(a-t)]])
        print pscl(d[i])[t]
        break

Submission status: Wrong Answer

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
# cnt:カウンター
cnt = 0

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

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

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    while i <= B and V[-i] == min(S):
        C = C + math.factorial(cnt) / ( math.factorial(cnt - i) * math.factorial(i))
        i += 1
    

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))

Submission status: Wrong Answer

Solution code:
import itertools
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[0:A]
ave = sum(S) / A
print(ave)

if min(V) == max(V): # もしも商品価値が全て同じだったら
    for i in range(A,B):
        C = C + len(list(itertools.combinations(V, i)))

else: # 商品価値が均一でなかったのなら
    Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
    Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか
    
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Submission status: Wrong Answer

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] != goods[i]: break
        total += comb(lastcount, i + 1)

print(avg)
print(total)

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 sum(pscl(d[i])[t:min(d[i],b-(a-t))+1])
        break

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 sum(pscl(d[i])[t:min(d[i],b-(a-t))])
        break

Submission status: Wrong Answer

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

from math import factorial


def comb(n, r):
    return 2


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, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)