Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPM(i, n, a) for (int i = ((n)-1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i, j, H, W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream &operator>>(istream &ist, pair<T, U> &right) {
  return ist >> right.first >> right.second;
}
template <class T, class U>
ostream &operator<<(ostream &ost, const pair<T, U> &right) {
  return ost << right.first << ' ' << right.second;
}
template <class T, class TCompatible, size_t N>
void Fill(T (&dest)[N], const TCompatible &val) {
  fill(begin(dest), end(dest), val);
}
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T (&dest)[M][N], const TCompatible &val) {
  for (int i = 0; i < M; ++i)
    Fill(dest[i], val);
}

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "Global.h"
#include "Graph.h"
#include "IntMod.h"
#include "Range.h"
#include "Union_Find.h"
#endif

#if 1234567891
#include <array>
#include <unordered_map>
#include <unordered_set>
template <typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // コスト小を優先
#endif

int N, K;
int A[100000], B[100000];
multiset<int> M;
int main() {
  cin >> N;
  REP(i, 0, N) {
    cin >> A[i];
    M.insert(A[i]);
  }
  cin >> K;
  REP(i, 0, K) { cin >> B[i]; }
  bool ok = true;
  REP(i, 0, K) {
    auto it = M.find(B[i]);
    if (it == M.end()) {
      ok = false;
      break;
    } else {
      M.erase(it);
    }
  }
  cout << YESNO(ok) << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPM(i, n, a) for (int i = ((n)-1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i, j, H, W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream &operator>>(istream &ist, pair<T, U> &right) {
  return ist >> right.first >> right.second;
}
template <class T, class U>
ostream &operator<<(ostream &ost, const pair<T, U> &right) {
  return ost << right.first << ' ' << right.second;
}
template <class T, class TCompatible, size_t N>
void Fill(T (&dest)[N], const TCompatible &val) {
  fill(begin(dest), end(dest), val);
}
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T (&dest)[M][N], const TCompatible &val) {
  for (int i = 0; i < M; ++i)
    Fill(dest[i], val);
}

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "Global.h"
#include "Graph.h"
#include "IntMod.h"
#include "Range.h"
#include "Union_Find.h"
#endif

#if 1234567891
#include <array>
#include <unordered_map>
#include <unordered_set>
template <typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // コスト小を優先
#endif

int N, K;
int A[200000], B[200000];
multiset<int> M;
int main() {
  cin >> N;
  REP(i, 0, N) {
    cin >> A[i];
    M.insert(A[i]);
  }
  cin >> K;
  REP(i, 0, K) { cin >> B[i]; }
  bool ok = true;
  REP(i, 0, K) {
    auto it = M.find(B[i]);
    if (it == M.end()) {
      ok = false;
      break;
    } else {
      M.erase(it);
    }
  }
  cout << YESNO(ok) << endl;
  return 0;
}