From cb71cda2666d6cff54cab58b1a5a3f1a4f06c91c Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:56:26 +0800 Subject: [PATCH] new file: P2887.cpp --- P2887.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 P2887.cpp diff --git a/P2887.cpp b/P2887.cpp new file mode 100644 index 0000000..f3df234 --- /dev/null +++ b/P2887.cpp @@ -0,0 +1,33 @@ +// 110 +#include +using namespace std; +int n, m; +pair s[2505]; +pair spf[2505]; +int main() +{ + scanf("%d%d", &n, &m); + for (int i = 1; i <= n; ++i) + scanf("%d%d", &s[i].first, &s[i].second); // min max + sort(s + 1, s + n + 1, [](pair x, pair y) + { return x.second > y.second; }); // 按 max 降序 + for (int i = 1; i <= m; ++i) + scanf("%d%d", &spf[i].first, &spf[i].second); + sort(spf + 1, spf + m + 1, [](pair x, pair y) + { return x.first > y.first; }); // 按 spf 降序 + + int point = 1; + priority_queue> q; // 按 min 降序 + int ans = 0; + for (int i = 1; i <= m; ++i) + { + while (point <= n && s[point].second >= spf[i].first) + q.push(s[point++]); + while (!q.empty() && q.top().first > spf[i].first) + q.pop(); + while (!q.empty() && spf[i].second > 0) + q.pop(), spf[i].second--, ans++; + } + printf("%d\n", ans); + return 0; +} \ No newline at end of file