#include #include #include #include using namespace std; int main () { int N, M; cin >> N >> M; vector A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; map mma, non_mma; for (int i = 0; i < M; i++) { int T, C; cin >> T >> C; if (T == 0) { non_mma[C]++; } if (T == 1) { mma[C]++; } } enum TYPE { MMA, NON_MMA, }; vector is_sold(N, false); vector> items; // (idx, type, cost) for (int i = 0; i < N; i++) { items.push_back(make_tuple(i, MMA, B[i])); items.push_back(make_tuple(i, NON_MMA, A[i])); } sort(items.begin(), items.end(), [](tuple a, tuple b) { return get<2>(a) > get<2>(b); }); for (auto& v : items) { int idx = get<0>(v); TYPE type = get<1>(v); int cost = get<2>(v); // もう売れている if (is_sold[idx]) continue; // 誰も買えない if (mma.lower_bound(cost) == mma.end() && non_mma.lower_bound(cost) == non_mma.end()) continue; auto nit = non_mma.lower_bound(cost); auto it = mma.lower_bound(cost); if (type == MMA) { if (nit == non_mma.end()) { (it->second)--; if (it->second == 0) mma.erase(it); } else { (nit->second)--; if (nit->second == 0) non_mma.erase(nit); } } if (type == NON_MMA) { if (it == mma.end()) { (nit->second)--; if (nit->second == 0) non_mma.erase(nit); } else { (it->second)--; if (it->second == 0) mma.erase(it); } } is_sold[idx] = true; } int ans = 0; for (const auto& v : is_sold) if (!v) ans++; cout << ans << "\n"; }