0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 01:25:25 +00:00
OI-codes/Luogu/T275386/T275386.cpp

45 lines
835 B
C++

#include <iostream>
#include <algorithm>
#include <set>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, k, ans;
std::pair<int, int> a[N];
std::multiset<int> set;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
std::sort(a + 1, a + 1 + n, [&](const std::pair<int, int> &a, const std::pair<int, int> &b) {
return a.second < b.second;
});
for (int i = 1; i <= k; i++) set.insert(0);
for (int i = 1; i <= n; i++) {
auto it = set.upper_bound(a[i].first);
if (it != set.begin()) {
set.erase(--it);
set.insert(a[i].second);
ans++;
}
}
cout << ans << endl;
return 0;
}