防晒
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 2510; 4 typedef pair<int, int> PII; 5 PII a[N]; //牛的min和max 6 int main() { 7 int c, l; 8 cin >> c >> l; 9 for (int i = 0; i < c; i++) { 10 cin >> a[i].first >> a[i].second; 11 } 12 sort(a, a + c); 13 map<int, int> spf; 14 //first是点的下标,second是数量 15 for (int i = 0; i < l; i++) { 16 int sp, cover; 17 cin >> sp >> cover; 18 spf[sp] += cover; 19 } 20 int res = 0; 21 spf[0] = spf[1001] = c; //哨兵 22 for (int i = c - 1; i >= 0; i--) { 23 map<int, int>::iterator t = spf.upper_bound(a[i].second); 24 t--; 25 if (t -> first >= a[i].first && t -> first <= a[i].second) { 26 res++; 27 t -> second--; 28 if (t -> second == 0) { 29 spf.erase(t); 30 } 31 32 } 33 } 34 cout << res << endl; 35 return 0; 36 }