Problem: 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.

Submission attempts (in order):
if __name__ == '__main__':
    from collections import Counter
    from scipy.misc import comb

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

    V.sort(reverse = True)
    max_list = V[0:A]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max < a:
            max_list = V[0:i]
            max = a
    print("{:.6f}".format(max))

    ans = 1
    max_list = Counter(max_list).most_common()
    for i in range(len(max_list)):
        ans *= comb(V.count(max_list[i][0]),max_list[i][1])
    print(int(ans))


if __name__ == '__main__':
    from collections import Counter
    from scipy.misc import comb

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))


if __name__ == '__main__':
    from collections import Counter
    from scipy.mist import comb

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))


if __name__ == '__main__':
    from collections import Counter
    from mist.special import comb

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))
    
    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))


def comb(n, k):
    return factorial(n) // (factorial(k) * factorial(n-k))
  
if __name__ == '__main__':
    from collections import Counter
    from math import factorial

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

    V.sort(reverse = True)
    max_list = [V[0:A]]
    max = sum(V[0:A]) / A

    for i in range(A+1,B+1):
        a = sum(V[0:i]) / i
        if max <= a:
            max_list.append(V[0:i])
            max = a
    print("{:.6f}".format(max))

    ans = 0
    for x in max_list:
        ans_sub = 1
        try:
            x = Counter(x).most_common()
        except TypeError:
            ans += ans_sub
            continue
        for i in range(len(x)):
            ans_sub *= comb(V.count(x[i][0]),x[i][1])
        ans += ans_sub
    print(int(ans))


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted