Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout << ans << endl;
#define COYE cout << "YES" << endl;
#define COYe cout << "Yes" << endl;
#define COye cout << "yes" << endl;
#define CONO cout << "NO" << endl;
#define CONo cout << "No" << endl;
#define COno cout << "no" << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define ALL(V) ((V).begin(), (V).end())
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0};
using namespace std;

int main() {
  int N, ans = 0;
  cin >> N;
  vector<int> L;
  REP(i, 2 * N) {
    int a;
    cin >> a;
    L.emplace_back(a);
  }

  SORT(L);
  REP(i, N) ans += L.at(2 * i - 2);

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout << ans << endl;
#define COYE cout << "YES" << endl;
#define COYe cout << "Yes" << endl;
#define COye cout << "yes" << endl;
#define CONO cout << "NO" << endl;
#define CONo cout << "No" << endl;
#define COno cout << "no" << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define ALL(V) ((V).begin(), (V).end())
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0};
using namespace std;

int main() {
  int N, ans = 0;
  cin >> N;
  vector<int> L;
  REP(i, 2 * N) {
    int a;
    cin >> a;
    L.emplace_back(a);
  }

  SORT(L);
  REP(i, N) ans += L.at(2 * i);

  cout << ans << endl;
  return 0;
}