#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int i; int value; Node(int i = -1, int value = -1) { this->i = i; this->value = value; } bool operator>(const Node &n) const { return value > n.value; } }; int main() { int N, M; cin >> N >> M; vector A(N); vector B(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < N; ++i) { cin >> B[i]; } vector C[2]; for (int i = 0; i < M; ++i) { int t, c; cin >> t >> c; C[t].push_back(c); } sort(C[0].begin(), C[0].end()); priority_queue , greater> pque_a; bool checked[N]; memset(checked, false, sizeof(checked)); int cnt = 0; for (int i = 0; i < N; ++i) { pque_a.push(Node(i, A[i])); } priority_queue , greater> stock; for (int c : C[0]) { while (not pque_a.empty() && pque_a.top().value <= c) { int i = pque_a.top().i; pque_a.pop(); stock.push(Node(i, -B[i])); } if (not stock.empty()) { Node n = stock.top(); stock.pop(); checked[n.i] = true; cnt++; } } sort(C[1].begin(), C[1].end()); reverse(C[1].begin(), C[1].end()); priority_queue , greater> pque_b; for (int i = 0; i < N; ++i) { if (not checked[i]) { pque_b.push(Node(i, -B[i])); } } for (int c : C[1]) { while (not pque_b.empty()) { int i = pque_b.top().i; pque_b.pop(); if (B[i] <= c) { checked[i] = true; cnt++; break; } } } cout << N - cnt << endl; return 0; }