Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #include <set>
- using namespace std;
- using namespace std;
- const long long mod=1e9+7;
- int main() {
- ios::sync_with_stdio(false);
- int n, k;
- cin >> n >> k;
- vector<pair<int, int>> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i].second >> v[i].first;
- }
- sort(v.begin(), v.end());
- multiset<int> ms;
- for(int i = 0; i < k; i++) {
- ms.insert(0);
- }
- int result = 0;
- for(int i = 0; i < n; i++) {
- int S = v[i].second;
- int E = v[i].first;
- multiset<int>::iterator it = ms.upper_bound(S);
- if(it != ms.begin()) {
- it--;
- ms.erase(it);
- ms.insert(E + 1);
- result++;
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement