Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for (i = 0; i < n; i++)
#define REPR(i, n) for (i = n; i >= 0; i--)
#define FOR(i, m, n) for (i = m; i < n; i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

ll memo[51][51];

ll comb(ll n, ll k) {
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  if (memo[n][k] != 0)
    return memo[n][k];
  return memo[n][k] = comb(n - 1, k) + comb(n - 1, k - 1);
}

ll modpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main(void) {
  ll N, A, B, i;
  cin >> N >> A >> B;
  double v[51];

  for (i = 1; i <= N; i++) {
    cin >> v[i];
    v[i] = -v[i];
  }
  sort(v + 1, v + N + 1);
  double sum = 0;
  for (i = 1; i <= A; i++) {
    sum += v[i];
  }
  ll cnt = 0;
  ll j = 1;
  for (i = 1; i <= N; i++) {
    if (v[i] == v[A]) {
      cnt++;
      if (cnt == 1)
        j = i;
    }
  }

  printf("%f\n", (-sum) / A);
  ll tmp = 0;
  if (j == 1) {
    for (i = A; i <= B; i++) {
      tmp += comb(cnt, i);
    }

    prin(tmp);
  } else
    prin(comb(cnt, A - j + 1));
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for (i = 0; i < n; i++)
#define REPR(i, n) for (i = n; i >= 0; i--)
#define FOR(i, m, n) for (i = m; i < n; i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

ll memo[51][51];

ll comb(ll n, ll k) {
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  if (memo[n][k] != 0)
    return memo[n][k];
  return memo[n][k] = comb(n - 1, k) + comb(n - 1, k - 1);
}

ll modpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main(void) {
  ll N, A, B, i;
  cin >> N >> A >> B;
  double v[51];

  for (i = 1; i <= N; i++) {
    cin >> v[i];
    v[i] = -v[i];
  }
  sort(v + 1, v + N + 1);
  double sum = 0;
  for (i = 1; i <= A; i++) {
    sum += v[i];
  }
  ll cnt = 0;
  ll j = 1;
  for (i = 1; i <= N; i++) {
    if (v[i] == v[A]) {
      cnt++;
      if (cnt == 1)
        j = i;
    }
  }

  printf("%f\n", (-sum) / A);
  ll tmp = 0;
  if (j == 1) {
    for (i = A; i <= min(B, cnt); i++) {
      tmp += comb(cnt, i);
    }

    prin(tmp);
  } else
    prin(comb(cnt, A - j + 1));
}