Problem p03776 (python)

Fixed submission:
from collections import Counter
from collections import Counter
N, A, B = (list)(map(int, input().split()))
v = (list)(map(int, input().split()))

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def comb(n, r):
    r = min(r, n-r)
    ret = 1
    for i in range(r):
        ret *= (n-i)/(i+1)
    return ret


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    double v[n];
    map<double, int, greater<double>> mp;
    rep (i, 0, n) {
        cin >> v[i];
        mp[v[i]]++;
    }
    int cnt = 0;
    double sum = 0;
    ll ans = 1;
    double ave = 0;
    for (auto p : mp) {
        if (cnt + p.second < a) {
            sum += p.second * p.first;
            cnt += p.second;
        } else if (a <= cnt + p.second) {
            if (cnt == 0) {
                ans=0;
                rep(k,A,min(B,p.second)+1){
                    ll tmp=1;
                    rep (i, 1, p.second + 1) tmp *= i;
                    rep (i, 1, k + 1) tmp /= i;
                    rep (i, 1, p.second - k + 1) tmp /= i;
                    ans+=tmp;
                }
                ave = p.first;

            } else {
                int cnt2 = a - cnt;
                rep (i, 1, p.second + 1) ans *= i;
                rep (i, 1, cnt2 + 1) ans /= i;
                rep (i, 1, p.second - cnt2 + 1) ans /= i;
                ave = (sum + cnt2 * p.first) / a;
            }
            break;
        }
    }
    cout << fixed << setprecision (15) << ave << "\n" << ans << "\n";
}

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial

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

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()

assert 1==2

tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val
        assert tmp_num<A

assert 1==2

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
from operator import mul
from functools import reduce

def comb(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 = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        assert val!=rest
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
from operator import mul
from functools import reduce

def comb(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 = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert 1==2
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
from scipy.special import comb
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num
        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val

assert 1==2

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    assert 1==2
    print(tmp_sum/tmp_num)
    print(1)
else:
    assert 1==2
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B+1,CC+1)):
        ans+=factorial(CC)//factorial(v)//factorial(CC-v)
    print(max_val)
    print(ans)
    exit()


tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
        if tmp_num>=A:
            break
    else:
        break

if A<=tmp_num<=B:
    print(tmp_sum/tmp_num)
    print(1)
else:
    assert 1==2
    rest=A-tmp_num
    tmp_num+=rest
    tmp_sum+=key*rest
    print(tmp_sum/tmp_num)
    print(factorial(val)//factorial(rest)//factorial(val-rest))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

tmp_sum=0
tmp_num=0


for key in sorted(V_C.keys(),reverse=True):
    val = V_C[val]
    if tmp_num+val<=B:
        tmp_num+=val
        tmp_sum+=key*val
    if tmp_num>=A:
        break
else:
    #A個になるまで追加する
    exit()

print(tmp_sum/tmp_num)
print(1)