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 sys
from collections import deque
import math
import numpy as np


def main():
    def perm(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    d = [0] * N
    q = []
    d[:] = map(int, input().split())
    dic={}
    dic_d = {}
    k = 0
    d.sort(reverse=True)
    s = sum(d[:A])
    m = s/A
    for i in set(d):
        dic_d[i] = d.count(i)
            
        
    print(m)
    
    
    for i in set(d):
        
        l = len(q)
        
        if l > 0:
            for j in range(l):
                for h in range(len(dic[q[j]])):
                    if dic[q[j]][h][0] >= B:
                        break
                    s = q[j] * dic[q[j]][h][0] + i
                    ave = s/(dic[q[j]][h][0]+1)
                    
                    if not ave in q:
                        dic[ave] = []
                        q.append(ave)
                        dic[ave].append([dic[q[j]][h][0]+1,dic[q[j]][h][1]])#[j]][g][1]] for g in range(len(dic[q[j]]))]
                    elif ave in q:
                        for g in range(len(dic[q[j]])):
                            ave_j = np.array(dic[ave])
                            if not dic[q[j]][g][0]+1 in ave_j[:,0]:
                                dic[ave].append([dic[q[j]][h][0]+1,dic[q[j]][h][1]])
                            else:
                                for f in range(len(dic[ave])):
                                    if dic[ave][f][0]  == dic[q[j]][g][0]+1:
                                        dic[ave][f][1] += 1
                            
                        
        if not i in q:
            q.append(i)
            dic[i] = []
            for h in range(1, dic_d[i]+1):
                
                dic[i].append([h,int(perm(dic_d[i],h))])
        elif i in q:
            for h in range(1,dic_d[i]+1):
                if dic[i][h][0] <= dic_d[i]:
                    dic[i][h][1] += perm(dic_d[i],dic[i][h][0])
                else:
                    dic[i].append([h, perm(dic_d[i],h)])
                    
    
    ave_np = np.array(dic[m])
    
    for i in range(len(dic[m])):
        if ave_np[i,0] <= B:
            ave_count = sum(ave_np[:i+1,1])
    print(ave_count)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
import numpy as np
from math import factorial

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
V = np.array(lr(), np.float64)
V.sort()
V = V[::-1]
Vcum = V.cumsum()
ave = Vcum / np.arange(1, N+1)
ma = ave[A-1:B].max()
print(ma)
cases = 0
Vrev = V[::-1]
for i, x in enumerate(ave[A-1:B], A-1):
    if x != ma:
        continue
    j = np.searchsorted(Vrev, V[i])
    k = np.searchsorted(Vrev, V[i], side='right')
    if j+1 == k:
        cases += 1
        continue
    r = i+1-j
    n = k-j
    a = factorial(n) / factorial(r) / factorial(n - r)
    cases += a

print(int(cases))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
import numpy as np
from math import factorial

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
V = np.array(lr(), np.float64)
V.sort()
V = np.flip(V)
Vcum = V.cumsum()
ave = Vcum / np.arange(1, N+1)
ma = ave[A-1:B].max()
print(ma)
cases = 0
Vrev = np.flip(V)
for i, x in enumerate(ave[A-1:B], A-1):
    if x != ma:
        continue
    j = np.searchsorted(Vrev, V[i])
    k = np.searchsorted(Vrev, V[i], side='right')
    if j+1 == k:
        cases += 1
        continue
    r = i+1-j
    n = k-j
    a = factorial(n) / factorial(r) / factorial(n - r)
    cases += a

print(int(cases))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v = sorted(v,reverse=True)

# (合計, 個数)
max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)


res = int(comb(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))

print(max_avg[0]/max_avg[1])
print(res)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;
map<int,int> lar;

signed main(){
    int N,A,B;cin>>N>>A>>B;
    vector<int>V(N);
    REP(i,N)cin>>V[i];
    sort(V.rbegin(),V.rend());
    double maxave=0;
    int stop=0;
    for(int i=A;i<=B;i++){
        double d=0;
        REP(j,i)d+=V[j];
        d/=A;
        maxave=max(d,maxave);
        if(V[i-1]!=V[i]){
            stop=i;
            break;
        }
    }
  	cout<<maxave<<endl;
    map<int,int>memo;
    int count=0;
  	for(int i=stop-1;i>=0;i--){
        if(V[i]=V[stop-1])count++;
    }
  	if(N!=count) cout<<count*(count-1)/2<<endl; 
  	else{
        int ans=0;
        for(int i=A;i<=B;i++){
            int ret=1;
            for(int j=0;j<i;j++){
              	ret*=(N-j);
              	ret/=(j+1);
            }
            ans+=ret;
        }
      	cout<<ans<<endl;
    }  	
}

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    c = Counter(v)
    
    base = 0
    num = []
    for i in range(min(A, B)):
        base += v[i]
        if not v[i] in num:
            num.append(v[i])
    ans = float(base) / float(min(A, B))
    te = []
    for i in range(len(num)):
        te.append(c[v[i]])
        
    exa = 1
    if(num[0] == num[-1]):
        exa = 0
        for i in range(A, B+1):
            exa += math.factorial(te[0])//(math.factorial(te[0]-i)*math.factorial(i))
    else:
        for i in range(len(te)):
            if(te[i] == 1):
                continue
            exa *= math.factorial(te[i])//(math.factorial(te[i]-A+1)*math.factorial(A-1))
            
    print(ans)
    print(exa)
main()

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    c = Counter(v)
    
    base = 0
    num = []
    for i in range(min(A, B)):
        base += v[i]
        if not v[i] in num:
            num.append(v[i])
    ans = float(base) / float(min(A, B))
    te = []
    for i in range(len(num)):
        te.append(c[v[i]])
        
    exa = 1
    if(len(te) == 1 and te[0] > 1):
        exa = 0
        for i in range(A, B+1):
            exa += math.factorial(te[0])//(math.factorial(te[0]-i)*math.factorial(i))
    else:
        for i in range(len(te)):
            if(te[i] == 1):
                continue
            exa *= math.factorial(te[i])//(math.factorial(te[i]-A+1)*math.factorial(A-1))
            
    print(ans)
    print(exa)
main()

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    c = Counter(v)
    
    base = 0
    num = []
    for i in range(min(A, B)):
        base += v[i]
        if not v[i] in num:
            num.append(v[i])
    ans = float(base) / float(min(A, B))
    te = []
    for i in range(len(num)):
        te.append(c[v[i]])
    
    exa = 1
    if(len(num) == 1):
        for i in range(1, num[0]):
            exa += math.factorial(N)//(math.factorial(N-i)*math.factorial(i))
    else:
        for i in range(len(te)):
            if(te[i] == 1):
                continue
            exa *= math.factorial(N-i)//(math.factorial(N-2*i-1)*math.factorial(i+1))
            
    print(ans)
    print(exa)
main()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque, Counter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

fac = [-1] * (10**2+1)

fac[0] = fac[1] = 1

def initNCM(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i

def NCM(n, r):
    return fac[n] / (fac[r] * fac[n-r])

initNCM(51)

def main():
    N, A, B = LI()
    v = sorted(LI())[::-1]
    cnt = Counter(v)
    selected = v[:A]
    print(sum(selected)/A)
    ans = 1
    used = 0
    for x in selected:
        used += cnt[x]
    used -= cnt[selected[-1]]
    ans = 0
    if len(selected) > 1:
        use_last = A - used
        ans += NCM(cnt[selected[-1]], use_last)
    else:
        for use_last in range(1, N+1):
            if not A <= used + use_last <= B:
                continue
            if use_last > cnt[selected[-1]]:
                continue
            ans += NCM(cnt[selected[-1]], use_last)
    print(int(ans))

main()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque, Counter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

fac = [-1] * (10**2+1)

fac[0] = fac[1] = 1

def initNCM(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i

def NCM(n, r):
    return fac[n] / (fac[r] * fac[n-r])

initNCM(51)

def main():
    N, A, B = LI()
    v = sorted(LI())[::-1]
    cnt = Counter(v)
    selected = v[:A]
    print(sum(selected)/A)
    ans = 1
    used = 0
    for x in selected:
        used += cnt[x]
    used -= cnt[selected[-1]]
    ans = 0
    if len(selected) > 1:
        use_last = A - used
        ans += NCM(cnt[selected[-1]], use_last)
    else:
        for use_last in range(1, N+1):
            if not A <= used + use_last <= B:
                continue
            if use_last > cnt[selected[-1]]:
                continue
            ans += NCM(cnt[selected[-1]], use_last)
    print(ans)

main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
from math import factorial

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
V = np.array(lr())
V.sort()
if A == 1:
    ave = V[-A]
else:
    ave = V[-A:].sum() / A
print(ave)
left_i = np.searchsorted(V, V[-A], side='left')
right_i = np.searchsorted(V, V[-A], side='right')
num = right_i - left_i
done = N - right_i

bottom = A-done
top = B-done

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

answer = combinations_count(num, bottom)
if ave == V[-A] and num > 1:
    for i in range(bottom+1, top+1):
        answer += combinations_count(num, i)

print(answer)
# 15

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
from math import sqrt

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, A, B = list(map(int, input().split()))
V = list(map(int, input().split()))

V.sort(reverse = True)

print(sum(V[:A]) / A)

# A番目と一緒の数字の数（A個より外で）
cnt_ext = 0
for i in range(A,min(A+B,N)):
  if V[A-1] == V[i]:
    cnt_ext += 1
    
# A番目と一緒の数字の数（A個の中で）
cnt_int = 0
for i in range(0,A):
  if V[A-1] == V[i]:
    cnt_int += 1
    
#print(cnt_int, cnt_ext)
cnt_all = cnt_int + cnt_ext

ans = 0
for i in range(A,B+1):
  ans += cmb(cnt_all, cnt_int)
  cnt_int += 1
  
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
def combi(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
x = V[-1]
ans = 0
for i in range(1,A+1):
    ans += V[-i]
    x = V[-i]
ans = ans/A
print(ans)
count = 0
import bisect
y = N - bisect.bisect(V,x)
if x == V[-1]:
    n = V.count(x)
    for i in range(A,min(B,V.count(x))+1):
        z = i - y
        count += comb(n,z)
else:
    z = A - y
    n = V.count(x)
    count += comb(n,z)
print(count)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,mini)
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = max(A + i - num2,0)
    ans  = int(ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i
    ans  = int(ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = int(A + i - num2)
    ans  = int(ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + math.factorial(kosuu))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans +  (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + math.factorial(n) / (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu)))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  

  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu))
  
  ave = sum(List[:A])/A
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
import bisect
import math

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,List[A-1])
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = ans + math.factorial(n) // (math.factorial(n - kosuu) * math.factorial(kosuu))
  
  ave = sum(List[:A])/A
  print(ave)
  print(ans)

Submission status: Runtime Error

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

def comb(n,r):
    return perm(n,r)//factorial(r)

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        for i in range(a,min(b,v)):
            value+=k*a
            cnt+=a
            nn=v
            kk=a
            ans=comb(nn, kk)
        break
if one_flg:
    ans=1
print(value/cnt)
print(ans)

Submission status: Runtime Error

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

def comb(n,r):
    return perm(n,r)//factorial(r)

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0
one_flg=False

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        if a==0 and v==1:
            one_flg=True
        elif b==v and b!=0:
            print(k)
            print(2**b-1)
            exit()
        else:
            for i in range(a,b+1):
                value+=k*i
                cnt+=i
                nn=v
                kk=i
                ans+=comb(nn, kk)
            break

if one_flg:
    ans=1
print(value/cnt)
print(ans)

Submission status: Runtime Error

Solution code:
# ABC057 D - Maximum Average Sets
from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)

def comb(n,r):
    return perm(n,r)//factorial(r)

n,a,b=nm()
V=nl()

d=defaultdict(int)
for vv in V:
    d[vv]+=1

value=0
cnt=0
ans=0

V=list(set(V))
if len(V)==1:
    print(V[0])
    print(2**(b-a+1)-1)
    exit()

for k,v in sorted(d.items(),key=lambda x:x[0],reverse=True):
    if a==0:
        if b==v:
            print(k)
            print(2**b-1)
            exit()
        break
    elif a>=v:
        value+=k*v
        cnt+=v
        a-=v
        b-=v
    elif a<v:
        for i in range(a,b):
            value+=k*i
            cnt+=i
            nn=v
            kk=i
            ans=comb(nn, kk)
        break
print(value/cnt)
print(ans)

Submission status: Runtime Error

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    #こっちが間違ってる
    m=min(v[0][1],B)
    for i in range(A,m+1):
        co-=combinations_count(v[0][1],i)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Runtime Error

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    #こっちが間違ってる
    m=min(v[0][1],B)
    co=2**m
    for i in range(A):
        co-=combinations_count(m,i)
    print(v[0][0])
    print(co)
    if A==m:
        r
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Runtime Error

Solution code:
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    m=min(v[0][1],B)
    co=2**m
    for i in range(A):
        co-=combinations_count(m,i)
    print(v[0][0])
    print(co)
else:
    r
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Submission status: Runtime Error

Solution code:
import math
from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

n,A,B=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
v=groupby(v)
if A<=v[0][1]:
    m=min(v[0][1],B)
    co=0
    #print(m-A)
    for i in range(A,m+1):
        co+=combinations_count(m,i)
        #co+=comb(m,A,exact=True)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    B=A
    k=1
    for i in range(l):
        B-=v[i][1]
        if B>=0:
            al+=(v[i][0]*v[i][1])
        else:
            B+=v[i][1]
            al+=(v[i][0]*B)
            k=combinations_count(v[i][1],B)
            #k=comb(v[i][1],B,exact=True)
    print(al/A)
    print(k)

Submission status: Runtime Error

Solution code:
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[-1]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
ans=0
if vmin[0]!=vmin[-1]:
    ans=f(mini+ex)//(f(mini)*f(ex))
    print(ans)
else:
    m=min(nab[2]-nab[1],ex)
    for i in range(m+1):
        ans+=f(mini+m)//(f(mini+i)*f(m-i))
    print(ans)

Submission status: Runtime Error

Solution code:
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[-1]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
ans=0
if vmin[0]!=vmin[-1]:
    ans=int(f(mini+ex)/(f(mini)*f(ex)))
    print(ans)
else:
    m=min(nab[2]-nab[1],ex)
    for i in range(m+1):
        ans+=int(f(mini+m)/(f(mini+i)*f(m-i)))
    print(ans)

Submission status: Runtime Error

Solution code:
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[0]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
m=min(nab[2]-nab[1],ex)
ans=int(f(min+ex)/(f(min)*f(ex)))
print(ans)

Submission status: Runtime Error

Solution code:
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if len(vmin)>1:
    for i in range(nab[1]):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
if nab[1]<nab[2]:
    for i in range(nab[0]-nab[1]):
        if v[nab[1]+i]==vmin[-1]:
            ex+=1
        else:
            break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
m=min(nab[2]-nab[1],ex)
ans=1
for i in range(m):
    ans+=int(f(mini+m)/(f(mini+i)*f(m-i)))
print(ans)