Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <bits/stdc++.h>
- using namespace std;
- const long long maxn =1e6+10;
- const long long mod=1e9+7;
- int main()
- {
- ///ifstream cin("haircut.in");
- ///ofstream cout("haircut.out");
- ios_base::sync_with_stdio(false); cin.tie(0);
- long long n,k;
- cin>>n>>k;
- vector<pair<long long,long long>>v;
- for(long long i=0;i<n;i++)
- {
- long long x,y;
- cin>>x>>y;
- v.push_back({y,x});
- }
- sort(v.begin(),v.end());
- multiset<long long>ms;
- while(k--)
- {
- ms.insert(0);
- }
- long long ans=0;
- for(long long i=0;i<n;i++)
- {
- multiset<long long>::iterator it = ms.upper_bound(v[i].second);
- if(it == ms.begin()) continue;
- it--;
- ms.erase(it);
- ms.insert(v[i].first);
- ans++;
- }
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement