틀린 풀이
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
vector<pair<ll, ll>> buy;
vector<pair<ll, int>> sell;
for (int i = 0; i < N; ++i) {
ll l, r;
cin >> l >> r;
buy.push_back({ l, r});
}
for (int i = 0; i < M; ++i) {
ll p; int x;
cin >> p >> x;
sell.push_back({ p,x });
}
sort(buy.begin(), buy.end());
sort(sell.begin(), sell.end());
int answer = 0;
while ((!buy.empty()) && (!sell.empty())) {
ll l = buy.back().first;
ll r = buy.back().second;
ll p = sell.back().first;
int& x = sell.back().second;
if (l > p) {
buy.pop_back();
continue;
}
if (r < p) {
sell.pop_back();
continue;
}
answer++;
buy.pop_back();
x--;
if (x == 0) {
sell.pop_back();
}
}
cout << answer;
return 0;
}