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

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted