Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

#define Rep(i, n) for (int i = 0; i < (n); i++)
#define For(i, n1, n2) for (int i = (n1); i < (n2); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n - 1); i >= 0; i--)
#define FOR(i, n1, n2) for (ll i = (n1); i < (n2); i++)
#define put(a) cout << (a) << "\n";
#define all(a) (a).begin(), (a).end();
#define SORT(a) sort((a).begin(), (a).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
#define oorret 0
#define oor(x)                                                                 \
  [&]() {                                                                      \
    try {                                                                      \
      x;                                                                       \
    } catch (const out_of_range &oor) {                                        \
      return oorret;                                                           \
    }                                                                          \
    return x;                                                                  \
  }()

typedef long long ll;
typedef pair<int, int> P;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int n, m;

int main() {
  cin >> n;
  vector<int> d(n);
  REP(i, n) { cin >> d[i]; }
  cin >> m;
  vector<int> t(n);
  unordered_map<int, int> mp;
  REP(i, m) {
    cin >> t[i];
    mp[t[i]]++;
  }
  REP(i, n) {
    auto itr = mp.find(d[i]);
    if (itr != mp.end()) {
      if (mp[d[i]] > 0) {
        mp[d[i]]--;
      }

    } else {
      // mp[d[i]];
    }
  }
  bool flag = true;
  REP(i, m) {
    if (mp[t[i]] > 0) {
      flag = false;
      break;
    }
  }
  if (flag) {
    put("YES");
  } else {
    put("NO");
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

#define Rep(i, n) for (int i = 0; i < (n); i++)
#define For(i, n1, n2) for (int i = (n1); i < (n2); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n - 1); i >= 0; i--)
#define FOR(i, n1, n2) for (ll i = (n1); i < (n2); i++)
#define put(a) cout << (a) << "\n";
#define all(a) (a).begin(), (a).end();
#define SORT(a) sort((a).begin(), (a).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
#define oorret 0
#define oor(x)                                                                 \
  [&]() {                                                                      \
    try {                                                                      \
      x;                                                                       \
    } catch (const out_of_range &oor) {                                        \
      return oorret;                                                           \
    }                                                                          \
    return x;                                                                  \
  }()

typedef long long ll;
typedef pair<int, int> P;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int n, m;

int main() {
  cin >> n;
  vector<int> d(n);
  REP(i, n) { cin >> d[i]; }
  cin >> m;
  vector<int> t(m);
  unordered_map<int, int> mp;
  REP(i, m) {
    cin >> t[i];
    mp[t[i]]++;
  }
  REP(i, n) {
    auto itr = mp.find(d[i]);
    if (itr != mp.end()) {
      if (mp[d[i]] > 0) {
        mp[d[i]]--;
      }

    } else {
      // mp[d[i]];
    }
  }
  bool flag = true;
  REP(i, m) {
    if (mp[t[i]] > 0) {
      flag = false;
      break;
    }
  }
  if (flag) {
    put("YES");
  } else {
    put("NO");
  }
  return 0;
}