Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define ALL(a) (a).begin(), (a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  EACH(x, vec) is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  REP(i, vec.size()) {
    if (i)
      os << " ";
    os << vec[i];
  }
  return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
  REP(i, vec.size()) {
    if (i)
      os << endl;
    os << vec[i];
  }
  return os;
}

const ll mod = linf;
ll mul(ll a, ll b) { return a * b % mod; }
ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b + mod) % mod; }
ll power(ll x, ll n) {
  ll res = 1;
  for (ll i = 1; i <= n; i <<= 1) {
    if (i & n)
      res = mul(res, x);
    x = mul(x, x);
  }
  return res;
}
ll inv(ll n) { return power(n, mod - 2); }
ll divi(ll a, ll b) { return mul(a, inv(b)); }
vector<ll> fact;
void init_fact(ll n) {
  fact.assign(n + 1, 1);
  FOR(i, 1, fact.size()) { fact[i] = mul(fact[i - 1], i); }
}
vector<vector<ll>> memo;
ll comb(ll n, ll r) {
  if (n == r || r == 0)
    return 1;
  if (memo[n][r] >= 0)
    return memo[n][r];
  return memo[n][r] = comb(n - 1, r) + comb(n - 1, r - 1);
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll n, A, B;
  cin >> n >> A >> B;
  memo.assign(100, vector<ll>(100, -1));
  vector<ll> v(n);
  cin >> v;
  sort(ALL(v), greater<ll>());
  ll sum = 0;
  REP(i, A) sum += v[i];
  ll m = v[A - 1];
  ll cnt1 = 0, cnt2 = 0;
  REP(i, A) {
    if (v[i] == m) {
      ++cnt1;
      ++cnt2;
    }
  }
  FOR(i, A, n) {
    if (v[i] == m)
      ++cnt1;
  }
  cout << fixed << setprecision(10);
  if (sum / A / 10 > 0)
    cout << sum / A / 10;
  cout << sum / A % 10 + (ld)(sum % A) / A << endl;
  if (cnt2 < A) {
    cout << comb(cnt1, cnt2) << endl;
  } else {
    ll a = 0;
    FOR(i, A, B + 1) { a += comb(cnt1, i); }
    cout << a << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define ALL(a) (a).begin(), (a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  EACH(x, vec) is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  REP(i, vec.size()) {
    if (i)
      os << " ";
    os << vec[i];
  }
  return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
  REP(i, vec.size()) {
    if (i)
      os << endl;
    os << vec[i];
  }
  return os;
}

const ll mod = linf;
ll mul(ll a, ll b) { return a * b % mod; }
ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b + mod) % mod; }
ll power(ll x, ll n) {
  ll res = 1;
  for (ll i = 1; i <= n; i <<= 1) {
    if (i & n)
      res = mul(res, x);
    x = mul(x, x);
  }
  return res;
}
ll inv(ll n) { return power(n, mod - 2); }
ll divi(ll a, ll b) { return mul(a, inv(b)); }
vector<ll> fact;
void init_fact(ll n) {
  fact.assign(n + 1, 1);
  FOR(i, 1, fact.size()) { fact[i] = mul(fact[i - 1], i); }
}
vector<vector<ll>> memo;
ll comb(ll n, ll r) {
  if (n == r || r == 0)
    return 1;
  if (r > n || r < 0)
    return 0;
  if (memo[n][r] >= 0)
    return memo[n][r];
  return memo[n][r] = comb(n - 1, r) + comb(n - 1, r - 1);
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll n, A, B;
  cin >> n >> A >> B;
  memo.assign(100, vector<ll>(100, -1));
  vector<ll> v(n);
  cin >> v;
  sort(ALL(v), greater<ll>());
  ll sum = 0;
  REP(i, A) sum += v[i];
  ll m = v[A - 1];
  ll cnt1 = 0, cnt2 = 0;
  REP(i, A) {
    if (v[i] == m) {
      ++cnt1;
      ++cnt2;
    }
  }
  FOR(i, A, n) {
    if (v[i] == m)
      ++cnt1;
  }
  cout << fixed << setprecision(10);
  if (sum / A / 10 > 0)
    cout << sum / A / 10;
  cout << sum / A % 10 + (ld)(sum % A) / A << endl;
  if (cnt2 < A) {
    cout << comb(cnt1, cnt2) << endl;
  } else {
    ll a = 0;
    FOR(i, A, B + 1) { a += comb(cnt1, i); }
    cout << a << endl;
  }
}