Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

struct edge {
  int /*from,*/ to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
// static const int INF = 2147483647;
// static const long long INF = 9223372000000000000;
// static const long long INF = 9223372000000000000/2;
// static const int INF = 1000010000;
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(), (x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a, b, c) max((a), max((b), (c)))
#define MIN(a, b, c) min((a), min((b), (c)))
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define int ll

int C[51][51];

void comb_table(int N) {
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        C[i][j] = 1;
      } else {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
      }
    }
  }
}

signed main() {
  int n, a, b, v[51];
  scanf("%lld%lld%lld", &n, &a, &b);
  comb_table(n);
  REP(i, n) scanf("%lld", &v[i]);
  sort(v, v + n);
  reverse(v, v + n);

  bool rullonz = (v[0] == v[a - 1]);
  double ave = 0;
  int cnt = 0;
  REP(i, a) {
    ave += (double)v[i];
    if (v[i] == v[a - 1])
      cnt++;
  }
  ave /= double(a);
  printf("%llf\n", ave);

  if (rullonz) {
    int k = 0;
    REP(i, n) if (v[i] == v[0]) k++;
    int ans = 0;
    for (int i = a; i <= min(b, k); i++) {
      ans += C[k][i];
    }
    printf("%lld\n", ans);
  } else {
    int k = 0;
    REP(i, n) if (v[i] == v[a - 1]) k++;
    printf("%lld\n", C[k][cnt]);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

struct edge {
  int /*from,*/ to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
// static const int INF = 2147483647;
// static const long long INF = 9223372000000000000;
// static const long long INF = 9223372000000000000/2;
// static const int INF = 1000010000;
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(), (x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a, b, c) max((a), max((b), (c)))
#define MIN(a, b, c) min((a), min((b), (c)))
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define int ll

int C[51][51];

void comb_table(int N) {
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        C[i][j] = 1;
      } else {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
      }
    }
  }
}

signed main() {
  int n, a, b, v[51];
  scanf("%lld%lld%lld", &n, &a, &b);
  comb_table(n);
  REP(i, n) scanf("%lld", &v[i]);
  sort(v, v + n);
  reverse(v, v + n);

  bool rullonz = (v[0] == v[a - 1]);
  double ave = 0;
  int cnt = 0;
  REP(i, a) {
    ave += (double)v[i];
    if (v[i] == v[a - 1])
      cnt++;
  }
  ave /= double(a);
  printf("%lf\n", ave);

  if (rullonz) {
    int k = 0;
    REP(i, n) if (v[i] == v[0]) k++;
    int ans = 0;
    for (int i = a; i <= min(b, k); i++) {
      ans += C[k][i];
    }
    printf("%lld\n", ans);
  } else {
    int k = 0;
    REP(i, n) if (v[i] == v[a - 1]) k++;
    printf("%lld\n", C[k][cnt]);
  }

  return 0;
}