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:
from scipy.misc import comb
import math
import copy

def nClr(n,l,r):
	ans = 0
	pat = 1
	if l == 0:
		ans += 1
		l += 1

	for i in range(l-1):
		pat *= ((n-i)/(i+1))

	for i in range(l-1,r):
		pat *= ((n-i)/(i+1))
		ans +=  pat

	return int(ans)

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

v.sort(reverse=True)

mean =float(sum(v[0:A]))/float(A)
print(sum(v[0:A]))
whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


if len(ran_A) == 1:
	n = min(B,whole[v[0]])
	num = nClr(whole[v[0]],A,n)
	print(mean)
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])


print(mean)
print(math.ceil(num))

Submission status: Wrong Answer

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

def nClr(n,l,r):
	ans = 0
	pat = 1
	if l == 0:
		ans += 1
		l += 1

	for i in range(l-1):
		pat *= ((n-i)/(i+1))

	for i in range(l-1,r):
		pat *= ((n-i)/(i+1))
		ans +=  pat

	return int(ans)

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

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


if len(ran_A) == 1:
	n = min(B,whole[v[0]])
	num = nClr(whole[v[0]],A,n)
	print("{0:.6f}".format(mean))
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])


print("{0:.6f}".format(mean))
print(math.ceil(num))

Submission status: Wrong Answer

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

def nClr(n,l,r):
	ans = 0
	pat = 1
	if l == 0:
		ans += 1
		l += 1

	for i in range(l-1):
		pat *= ((n-i)/(i+1))

	for i in range(l-1,r):
		pat *= ((n-i)/(i+1))
		ans +=  pat

	return int(ans)

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

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


if len(ran_A) == 1:
	n = min(B,whole[v[0]])
	num = nClr(n,A,n)
	print("{0:.6f}".format(mean))
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])


print("{0:.6f}".format(mean))
print(math.ceil(num))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import math
import copy
N,A,B =  map(int,input().split(" "))
v =  list(map(int,input().split(" ")))

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

if len(ran_A) == 1:
	num = (2 ** whole[v[0]]) - 1
	print("{0:.6f}".format(mean))
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])

print("{0:.6f}".format(mean))
print(math.ceil(num))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import copy
N,A,B =  map(int,input().split(" "))
v =  list(map(int,input().split(" ")))

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

if len(ran_A) == 1:
	num = (2 ** whole[v[0]]) - 1
	print("{0:.6f}".format(mean))
	print(int(num))
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])

print("{0:.6f}".format(mean))
print(int(num))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import copy
N,A,B =  map(int,input().split(" "))
v =  list(map(int,input().split(" ")))

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

if len(ran_A) == 1:
	num = (2 ** whole[v[0]]) - 1
	print(mean)
	print(int(num))
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])

print(mean)
print(int(num))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import copy
N,A,B =  map(int,input().split(" "))
v =  list(map(int,input().split(" ")))

v.sort(reverse=True)

mean = sum(v[0:A])/A

whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])

print(mean)
print(int(num))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,A,B = map(int, raw_input().split())
src = map(int, raw_input().split())
src.sort(reverse=True)
counter = Counter(src)

cums = [0]
for a in src:
  cums.append(cums[-1] + a)

maxave = 0.0
maxns = []
for n in range(A,B+1):
  ave = cums[n]*1.0 / n
  if ave > maxave:
    maxave = ave
    maxns = [n]
  elif ave == maxave:
    maxns.append(n)

ncr = [[1]]
for n in range(1,N+1):
  ncr.append([1])
  for r in range(1,n):
    ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
  ncr[n].append(1)

ans = 0
for n in maxns:
  last = src[n-1]
  r = 1
  for i in range(n-2,-1,-1):
    if src[i] == last:
      r += 1
    else:
      break
  ans += ncr[counter[last]][r]

print("{0:.10f}".format(maxave))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,A,B = map(int, raw_input().split())
src = map(int, raw_input().split())
src.sort()
counter = Counter(src)

cums = [0]
for a in reversed(src):
  cums.append(cums[-1] + a)

maxave = 0.0
maxns = []
for n in range(A,B+1):
  ave = cums[n]*1.0 / n
  if ave > maxave:
    maxave = ave
    maxns = [n]
  elif ave == maxave:
    maxns.append(n)

ncr = [[1]]
for n in range(1,N+1):
  ncr.append([1])
  for r in range(1,n):
    ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
  ncr[n].append(1)

ans = 0
for n in maxns:
  last = src[-n]
  r = 1
  while r < n and src[-n + r] == last:
    r += 1
  ans += ncr[counter[last]][r]

print("{0:.20f}".format(maxave))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,A,B = map(int, raw_input().split())
src = map(int, raw_input().split())
src.sort()
counter = Counter(src)

cums = [0]
for a in reversed(src):
  cums.append(cums[-1] + a)

maxave = 0.0
maxns = []
for n in range(A,B+1):
  ave = cums[n]*1.0 / n
  if ave > maxave:
    maxave = ave
    maxns = [n]
  elif ave == maxave:
    maxns.append(n)

ncr = [[1]]
for n in range(1,N+1):
  ncr.append([1])
  for r in range(1,n):
    ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
  ncr[n].append(1)

ans = 0
for n in maxns:
  last = src[-n]
  r = 1
  while r < n and src[-n + r] == last:
    r += 1
  ans += ncr[counter[last]][r]

print("{0:.10f}".format(maxave))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

v.sort(reverse = True)
cnt_v = Counter(v)
ave = []

for i in range(A, B+1):
    #ave = sum(v[0:i]) / i
    ave.append(sum(v[0:i]) / i)
#print(ave)

max_ave = max(ave)
ans = 0

for j in range(B-A+1):
    temp = 1
    if ave[j] == max_ave:
        #print(j)
        l = v[:A+j]
        cnt_l = Counter(l)
        for key, values in cnt_l.items():
            temp *= (math.factorial(cnt_v[key]) / math.factorial(values) / math.factorial(cnt_v[key] - values))
        ans += temp

print(max_ave)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import scipy.misc as scm

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

sorted_v = sorted(v)[::-1]

ans= sum(sorted_v[:A])/A

print(ans)


n = sorted_v.count(sorted_v[A-1]) 


if ans != sorted_v[A-1]:
    r = sorted_v[:A].count(sorted_v[A-1])
    print(int(scm.comb(n, r)))
    
else:
    C = 0
    for num in range(A, B+1):
#         print(num)
        if num <= n:
            C += (scm.comb(n, num))
        else :
            break
    print(int(C))

Submission status: Wrong Answer

Solution code:
from math import factorial

n, a, b = map(int, input().split(" "));
v = list(map(int, input().split(" ")))

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)

revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0;
if a > revpos:
    print(1);
else:
    for i in range(a-revpos, b-revpos+1):
        ans+=ncr(num, i);
    print(ans);

Submission status: Wrong Answer

Solution code:
from math import factorial

n, a, b = map(int, input().split(" "));
v = list(map(int, input().split(" ")))


def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

newv=sorted(v);
print(sum(newv[-a:])/a)

num=0;
for gap in range(0, b-a+1):
    num+=ncr(newv.count(newv[-a]), newv[-a-gap:-a].count(newv[-a]));

print(num);

Submission status: Wrong Answer

Solution code:
from math import factorial

n, a, b = map(int, input().split(" "));
v = list(map(int, input().split(" ")))


def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

newv=sorted(v);
print(sum(newv[-a:])/a)

print(ncr(newv.count(newv[-a]), newv[-a-b:-a].count(newv[-a])));

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, raw_input().split())
V = map(float, raw_input().split())
V.sort(reverse=True)

idx = V.index(V[A])
k = V.count(V[A])
avr = sum(V[:A]) / A
print "%f" % avr

def fact(n):
    if n < 1:
        return 1
    else:
        return n * fact(n-1)

if idx > 0:
    print k
else:
    cnt = 0
    for i in range(A, B+1):
        cnt += fact(k) / fact(i) / fact(k-i)
    print cnt

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import scipy.misc as scm
n,a,b = map(int, raw_input().split())
v = map(int, raw_input().split())

v = sorted(v)
ave = np.zeros(n+1)
ans = 0

for i in range(a,b+1):
    ave[i] = 1.0*sum(v[-i:])/i
print("{0:.6f}".format(ave.max()))
maxlist = np.where(ave == ave.max())
for i in maxlist[0]:
    l = v.count(min(v[-i:]))
    r = v[-i:].count(min(v[-i:]))
    ans += scm.comb(l,r)
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import scipy.misc as scm
n,a,b = map(int, raw_input().split())
v = map(int, raw_input().split())

v = sorted(v)
ave = np.zeros(n+1)
ans = 0

for i in range(a,b+1):
    ave[i] = 1.0*sum(v[-i:])/i
print(ave.max())
maxlist = np.where(ave == ave.max())
for i in maxlist[0]:
    l = v.count(min(v[-i:]))
    r = v[-i:].count(min(v[-i:]))
    ans += scm.comb(l,r)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import factorial as f

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

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print "%.16f" % mean
total = d[sub[0]]
choose = sub.count(sub[0])

ans = f(total*1.0)/(f(choose)*f(total-choose))
print "%.0f" % ans

Submission status: Wrong Answer

Solution code:
from math import factorial as f

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

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print "%.16f" % mean
total = d[sub[0]]
choose = sub.count(sub[0])

ans = f(total*1.0)/(f(choose)*f(total-choose))
print "%.16f" % ans

Submission status: Wrong Answer

Solution code:
from math import factorial as f

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

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print mean
total = d[sub[0]]
choose = sub.count(sub[0])

print f(total)/(f(choose)*f(total-choose))

Submission status: Wrong Answer

Solution code:
n,a,b = map(int, raw_input().split())
l = map(int, raw_input().split())
l.sort()

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print mean
print l[:-a].count(sub[0])+1

Submission status: Wrong Answer

Solution code:
n,a,b = map(int, raw_input().split())
l = map(int, raw_input().split())
l.sort()

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print mean
print d[sub[0]]-sub.count(sub[0])+1

Submission status: Wrong Answer

Solution code:
n,a,b = map(int, raw_input().split())
l = map(int, raw_input().split())
l.sort()

d = {}

for item in l:
    if item in d:
        d[item]+=1
    else:
        d[item] = 1

sub = l[-a:]


mean = sum(sub)/(a+0.0)

print mean
print d[sub[0]]

Submission status: Wrong Answer

Solution code:
import numpy as np
def comb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a-i)
    for i in range(b):
        ans /= (i+1)
    return ans
N, A, B = map(int, raw_input().split())
v = sorted(map(float, raw_input().split()))
value_num_mapping = {}
for _ in v:
    if not _ in value_num_mapping:
        value_num_mapping[_] = 0
    value_num_mapping[_] += 1

best = np.mean(v[-A:])
ans = 0
for T in range(A, B+1):
    if np.mean(v[-T:]) == best:
        cnt = len([_ for _ in v[-T:] if _ == v[-T]])
        ans += comb(value_num_mapping[v[-T]], cnt)
print best
print ans

Submission status: Wrong Answer

Solution code:
import numpy as np
def comb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a-i)
    for i in range(b):
        ans /= (i+1)
    return ans
N, A, B = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))
value_num_mapping = {}
for _ in v:
    if not _ in value_num_mapping:
        value_num_mapping[_] = 0
    value_num_mapping[_] += 1

best = np.mean(v[-A:])
ans = 0
for T in range(A, B+1):
    if np.mean(v[-T:]) == best:
        cnt = len([_ for _ in v[-T:] if _ == v[-T]])
        ans += comb(value_num_mapping[v[-T]], cnt)
print best
print ans

Submission status: Wrong Answer

Solution code:

def f1(i):
  if(i == 1):
    return 1
  return i*f1(i-1)

def f2(a, b):
  print(a, b)
  return f1(a)/(f1(b)*f1(a-b))
a = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

sorted_v = sorted(v)

b = []
c = {}

sum = 0
count = 0
for i in range(a[1]):
  b.append(sorted_v[a[0] - i -1])
  if(not sorted_v[a[0] - i -1] in c):
    c[sorted_v[a[0] - i -1]] = 1
  else:
    c[sorted_v[a[0] - i -1]] += 1
  sum += sorted_v[a[0] - i -1]
  count += 1

pattern = 1
memory = count

max = max(b)

if(max == sorted_v[a[0] - memory -1] and count == c[sorted_v[a[0] - memory -1]] ):
   tmp = c[max]
   while(max == sorted_v[a[0] - memory -1]):
     c[max] += 1
     memory += 1
     if(a[0] - memory -1 == -1):
        break
   if(c[max] > a[2]):
      pattern = 0
      pattern = f2(c[max], a[2])
   else:
      pattern = 1
   for i in range(a[1], min(c[max], a[2])):
     pattern += f2(c[max], i)


else:

    while(sorted_v[a[0] - memory -1] == b[-1] and count <= a[2]):
      pattern += c[sorted_v[a[0] - memory -1]]
      memory += 1
      if(a[0] - memory -1 == -1):
        break


print("{0:.7f}".format(sum/count))
print(pattern)

Submission status: Wrong Answer

Solution code:

def f1(i):
  if(i == 1):
    return 1
  return i*f1(i-1)

def f2(a, b):
  return f1(a)/(f1(b)*f1(a-b))
a = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

sorted_v = sorted(v)

b = []
c = {}

sum = 0
count = 0
for i in range(a[1]):
  b.append(sorted_v[a[0] - i -1])
  if(not sorted_v[a[0] - i -1] in c):
    c[sorted_v[a[0] - i -1]] = 1
  else:
    c[sorted_v[a[0] - i -1]] += 1
  sum += sorted_v[a[0] - i -1]
  count += 1

pattern = 1
memory = count

max = max(b)

if(max == sorted_v[a[0] - memory -1] and count == c[sorted_v[a[0] - memory -1]] ):
   tmp = c[max]
   while(max == sorted_v[a[0] - memory -1]):
     c[max] += 1
     memory += 1
     if(a[0] - memory -1 == -1):
        break
   if(c[max] > a[2]):
      pattern += f2(c[max], a[2])
   else:
      pattern = 1
   for i in range(tmp, min(c[max], a[2])):
     pattern += f2(c[max], i)


else:

    while(sorted_v[a[0] - memory -1] == b[-1] and count <= a[2]):
      pattern += c[sorted_v[a[0] - memory -1]]
      memory += 1
      if(a[0] - memory -1 == -1):
        break


print("{0:.7f}".format(sum/count))
print(pattern)

Submission status: Wrong Answer

Solution code:
import itertools

def f1(i):
  if(i == 1):
    return 1
  return i*f1(i-1)

def f2(a, b):
  return f1(a)/(f1(b)*f1(a-b))
a = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

sorted_v = sorted(v)

b = []
c = {}
mean = 0
sum = 0
count = 0
for i in range(a[1]):
  b.append(sorted_v[a[0] - i -1])
  if(not sorted_v[a[0] - i -1] in c):
    c[sorted_v[a[0] - i -1]] = 1
  else:
    c[sorted_v[a[0] - i -1]] += 1
  sum += sorted_v[a[0] - i -1]
  count += 1

pattern = 1
memory = count

max = max(b)

if(max == sorted_v[a[0] - memory -1] and count == c[sorted_v[a[0] - memory -1]] ):
   tmp = c[max]
   while(max == sorted_v[a[0] - memory -1]):
     c[max] += 1
     memory += 1
     if(a[0] - memory -1 == -1):
        break
   pattern = 1
   for i in range(tmp, min(c[max], a[2])):
     pattern += f2(c[max], i)


else:

    while(sorted_v[a[0] - memory -1] == b[-1] and count <= a[2]):
      pattern += c[sorted_v[a[0] - memory -1]]
      memory += 1

      print((pattern, c, memory))
      if(a[0] - memory -1 == -1):
        break


print("{0:.7f}".format(sum/count))
print(pattern)

Submission status: Wrong Answer

Solution code:
import itertools

def f1(i):
  if(i == 1):
    return 1
  return i*f1(i-1)

def f2(a, b):
  return f1(a)/(f1(b)*f1(a-b))
a = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

sorted_v = sorted(v)

b = []
c = {}
mean = 0
sum = 0
count = 0
for i in range(a[1]):
  b.append(sorted_v[a[0] - i -1])
  if(not sorted_v[a[0] - i -1] in c):
    c[sorted_v[a[0] - i -1]] = 1
  else:
    c[sorted_v[a[0] - i -1]] += 1
  sum += sorted_v[a[0] - i -1]
  count += 1

pattern = 1
memory = count

max = max(b)

if(max == sorted_v[a[0] - memory -1] and count == c[sorted_v[a[0] - memory -1]] ):
   tmp = c[max]
   while(max == sorted_v[a[0] - memory -1]):
     c[max] += 1
     memory += 1
     if(a[0] - memory -1 == -1):
        break
   pattern = 1
   for i in range(tmp, min(c[max], a[2])):
     pattern += f2(c[max], i)


else:

    while(sorted_v[a[0] - memory -1] == b[-1] and count <= a[2]):
      pattern += c[sorted_v[a[0] - memory -1]]
      memory += 1

      print((pattern, c, memory))
      if(a[0] - memory -1 == -1):
        break


print(sum/count)
print(pattern)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, raw_input().split())
V = sorted(map(int, raw_input().split()))
C = {}
for v in V:
    C[v] = C.get(v, 0) + 1

memo = {}
def comb(n, k):
    if n == k or k == 0:
        return 1
    if (n, k) in memo:
        return memo[n, k]
    res = memo[n, k] = comb(n-1, k) + comb(n-1, k-1)
    return res

su = 0
count = 0

cur = 0
tmp = 0
for k in sorted(C.keys(), reverse=True):
    if cur > b:
        break
    if cur+C[k] < a:
        cur += C[k]
        tmp += C[k]*k
    else:
        for c in xrange(max(a, cur), min(b, cur+C[k])+1):
            tmp_ = tmp + k*(c-cur)
            if su < tmp_/c:
                su = tmp_/c
                count = comb(C[k], c-cur)
            elif su == tmp_/c:
                count += comb(C[k], c-cur)
        cur += C[k]
        tmp += C[k]*k
print su
print count

Submission status: Wrong Answer

Solution code:
def ncr(n, r):
  res = 1
  for k in range(r):
    res *= n - k
    res //= k + 1
  return res
 
(n, a, b) = [int(x) for x in input().split(' ')]
v = [int(x) for x in input().split(' ')]
v.sort(reverse=True)
 
su = 0
avg = 0
for x in v[:a]:
  su += x
avg = su / a
 
comb = 0
cnt1 = v.count(v[a - 1])
cnt2 = v[:a].count(v[a - 1])
for i, vi in enumerate(v[a - 1:b]):
  if vi == v[a - 1]:
    comb += ncr(cnt1, cnt2 + i)

print(avg)
print(comb)

Submission status: Wrong Answer

Solution code:
def ncr(n, r):
  res = 1
  for k in range(r):
    res *= n - k
    res //= k + 1
  return res

(n, a, b) = [int(x) for x in input().split(' ')]
v = [int(x) for x in input().split(' ')]
v.sort()

su = 0
avg = 0
for x in v[-a:]:
  su += x
avg = su / a

comb = 0
cnt2 = v.count(v[-a])
if v[-a] != v[-1]:
  cnt1 = v[-a:].count(v[-a])
  comb = ncr(cnt2, cnt1)
else:
  for i in range(a, b + 1):
    cnt1 = v[-i:].count(v[-i])
    comb += ncr(cnt2, cnt1)

print(avg)
print(comb)

Submission status: Wrong Answer

Solution code:
N,A,B=[int(i) for i in input().split(" ")]
v=[int(i) for i in input().split(" ")]

v.sort()
v.reverse()

def average(l,a):
    sum=0
    for i in range(a):
        sum+=l[i]
    return (sum/a)


kaijoulist=[1,1]
def kaijou(n):
    t=len(kaijoulist)
    while t<=n:
        kaijoulist.append(kaijoulist[-1]*t)
        t+=1
    return kaijoulist[n]

def combination(n,k):
    return int(kaijou(n)/(kaijou(k)*kaijou(n-k)))



max_index=[A]
max=average(v,A)
for i in range(A+1,B+1):
    ave=average(v,i)
    if max<ave:
        max_index=[i-1]
        max=ave
    elif max==ave:
        max_index.append(i-1)

li_uniq = list(set(max_index))

answer=0
for i in li_uniq:
    x=v[i]
    kosuu=v.count(x)
    sentou=v.index(x)
    answer+=combination(kosuu,i-sentou+1)
print(max)
print(answer)

Submission status: Wrong Answer

Solution code:
#! coding: UTF-8
N,A,B = list(map(int,input().split(" ")))
V = list(map(int,input().split(" ")))
V.sort(reverse=True)
max_avr = sum(V[:A]) / A
a_num = V.count(V[A-1])
a_pos = V[:A].count(V[A-1])

#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

if V[0] == V[A-1]:
    cnt = sum(nCr(a_num,i) for i in range(A,min(B,a_num))) 
else:
    cnt = nCr(a_num,a_pos)
print("{0:.10f}".format(max_avr))
print(int(cnt))

Submission status: Wrong Answer

Solution code:
#! coding: UTF-8
N,A,B = list(map(int,input().split(" ")))
V = list(map(int,input().split(" ")))
V.sort(reverse=True)
max_avr = sum(V[:A]) / A
a_num = V.count(V[A-1])
a_pos = V[:A].count(V[A-1])

#確率統計nCr
import math
def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

if a_pos == A:
    cnt = sum(nCr(a_num,i) for i in range(A,min(B,a_num))) 
else:
    cnt = nCr(a_num,a_pos)
print("{0:.10f}".format(max_avr))
print(int(cnt))

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

N, A, B = list(map(int, input().split()))
V = np.array(list(map(int, input().split())))
V.sort()
V[:] = V[::-1]

def nCp(n, p):
    return(len(list(itertools.combinations(np.arange(n), p))))

d = V[A-1]
# unless all equal, we only need A
if d == V.max():
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    print(V[:A].mean())
    res = nCp(d_eq_cnt, A)
    res_sum = nCp(d_eq_cnt, A)
    for k in range(1, min(B, d_eq_cnt)+1):
        res = res * (d_eq_cnt - (A+k-1)) // (A+k)
        res_sum += res
    print(res_sum)
    
    
else:
    # count how many d
    d_eq_cnt = np.count_nonzero(V == d)
    d_lq_cnt = np.count_nonzero(V > d)
    print(V[:A].mean())
    print(nCp(d_eq_cnt, A - d_lq_cnt))

Submission status: Wrong Answer

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

num = [0 for x in range(N)]
total = [0 for x in range(N)]

for i, v in enumerate(L):
    for j in reversed(range(1, i + 1)):
        new_v = total[j - 1] + v
        if(new_v > total[j]):
            total[j] = new_v
            num[j] = num[j - 1]
        elif(new_v == total[j]):
            num[j] = num[j] + num[j - 1]

    if(v > total[0]):
        total[0] = v
        num[0] = 1
    elif(v == total[0]):
        num[0] = num[0] + 1

print(total)
total = [x / (i + 1) for i, x in enumerate(total)]
total = total[(A - 1):B]
num = num[(A - 1):B]

maxV = max(total)
maxNum = sum([j for i, j in zip(total, num) if i == maxV])
print(maxV)
print(maxNum)

Submission status: Wrong Answer

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

num_comb = [0 for x in range(N)]
avg_value = [0 for x in range(N)]

for i, v in enumerate(L):
    for j in reversed(range(i)):
        new_v = (avg_value[j] * (j + 1) + v) / (j + 2)
        if(new_v > avg_value[j + 1]):
            avg_value[j + 1] = new_v
            num_comb[j + 1] = num_comb[j]
        elif(new_v == avg_value[j + 1]):
            num_comb[j + 1] = num_comb[j + 1] + num_comb[j]

    if(v > avg_value[0]):
        avg_value[0] = v
        num_comb[0] = 1
    elif(v == avg_value[0]):
        num_comb[0] = num_comb[0] + 1

avg_value = avg_value[(A - 1):B]
num_comb = num_comb[(A - 1):B]

maxV = max(avg_value)
maxNum = sum([j for i, j in zip(avg_value, num_comb) if i == maxV])
print(maxV)
print(maxNum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections

def combinations(n, r):
    res = 1
    for i in xrange(n - r + 1, n + 1):
        res *= i
    for i in xrange(2, r + 1):
        res /= i
    return res

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

cnt = collections.defaultdict(int)
for vi in v:
    cnt[vi] += 1

mx = 0
comb = 0
for n in xrange(A, B + 1):
    x = v[:n]
    ave = sum(x)*1.0/n

    tmp_cnt = collections.defaultdict(int)
    for xi in x:
        tmp_cnt[xi] += 1

    tmp = 1
    for key, val in tmp_cnt.items():
        tmp *= combinations(cnt[key], val)

    if ave - mx > 1e-7:
        mx = ave
        comb = tmp
    elif abs(mx - ave) < 1e-7:
        comb += tmp 

print "%.10f" % mx
print comb

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections

def combinations(n, r):
    res = 1
    for i in xrange(n - r + 1, n + 1):
        res *= i
    for i in xrange(2, r + 1):
        res /= i
    return res

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

cnt = collections.defaultdict(int)
for vi in v:
    cnt[vi] += 1

mx = 0.0
comb = 0
for n in xrange(A, B + 1):
    x = v[:n]
    ave = sum(x)*1.0/n

    tmp_cnt = collections.defaultdict(int)
    for xi in x:
        tmp_cnt[xi] += 1

    tmp = 1
    for key, val in tmp_cnt.items():
        tmp *= combinations(cnt[key], val)

    if ave - mx > 1e-6:
        mx = ave
        comb = tmp
    elif abs(mx - ave) < 1e-6:
        comb += tmp 

print "%.10f" % mx
print comb

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)

    tri_subset = tri[A:B+1]
    print(sum(tri_subset))

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