Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
  for (; a != b; ++a)
    cerr << *a << ' ';
  cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif

template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

typedef long long int lint;
typedef pair<int, int> pi;

namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.fr << ',' << a.sc << ')';
  return out;
}
} // namespace std

// const int INF=5e8;
int n;
int ar[100005];
int main() {
  cin >> n;
  n *= 3;
  REP(i, n) cin >> ar[i];
  sort(ar, ar + n);
  int n3 = n / 3;
  lint res = 0;
  for (int i = n - 2; i >= n3; i -= 2)
    res += ar[i];
  cout << res << endl;
  return 0;
}


Fixed submission:
#define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
  for (; a != b; ++a)
    cerr << *a << ' ';
  cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif

template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

typedef long long int lint;
typedef pair<int, int> pi;

namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.fr << ',' << a.sc << ')';
  return out;
}
} // namespace std

// const int INF=5e8;
int n;
int ar[300005];
int main() {
  cin >> n;
  n *= 3;
  REP(i, n) cin >> ar[i];
  sort(ar, ar + n);
  int n3 = n / 3;
  lint res = 0;
  for (int i = n - 2; i >= n3; i -= 2)
    res += ar[i];
  cout << res << endl;
  return 0;
}