Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

// #define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ; // 何もしない文
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(x) ((int)(x).size()) // unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

// #define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T> std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}

const int MOD = 1e9 + 7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<PII> ab(N), cd(N);
  bool useda[105] = {};
  bool usedb[105] = {};
  REP(i, N) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    ab[i] = make_pair(tmpa, tmpb);
  }
  REP(i, N) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    cd[i] = make_pair(tmpa, tmpb);
  }
  sort(ab.begin(), ab.end());
  sort(cd.begin(), cd.end());
  int ans = 0;

  for (auto p : cd) {
    dump(p.first) dump(p.second) int wanta;
    int wantb = -1;
    for (auto q : ab) {
      dump(q.first) dump(q.second) if (q.first >= p.first) break;
      if (useda[q.first] == true) {
        dump("used!") continue;
      }

      if (q.second <= p.second && q.second > wantb) {
        wantb = q.second;
        wanta = q.first;
      }
    }
    if (wantb != -1) {
      dump("friend!") useda[wanta] = true;
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

// #define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ; // 何もしない文
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(x) ((int)(x).size()) // unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

// #define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T> std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}

const int MOD = 1e9 + 7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<PII> ab(N), cd(N);
  bool useda[205] = {};
  bool usedb[205] = {};
  REP(i, N) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    ab[i] = make_pair(tmpa, tmpb);
  }
  REP(i, N) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    cd[i] = make_pair(tmpa, tmpb);
  }
  sort(ab.begin(), ab.end());
  sort(cd.begin(), cd.end());
  int ans = 0;

  for (auto p : cd) {
    dump(p.first) dump(p.second) int wanta;
    int wantb = -1;
    for (auto q : ab) {
      dump(q.first) dump(q.second) if (q.first >= p.first) break;
      if (useda[q.first] == true) {
        dump("used!") continue;
      }

      if (q.second <= p.second && q.second > wantb) {
        wantb = q.second;
        wanta = q.first;
      }
    }
    if (wantb != -1) {
      dump("friend!") useda[wanta] = true;
      ans++;
    }
  }
  cout << ans << endl;
}