fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll=long long;
  5. //using int=long long;
  6. int const MAXN=2e5+10;
  7. int const INF=2e9+10;
  8. int n,k,ans;
  9.  
  10. void open(){
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL); cout.tie(NULL);
  13. // freopen(TASK".INP","r",stdin);
  14. // freopen(TASK".OUT","w",stdout);
  15. }
  16. pair<int,int> A[MAXN];
  17.  
  18. bool compareValue(pair<int,int> a,pair<int,int> b){
  19. return a.second<b.second;
  20. }
  21.  
  22. int main() {
  23. open();
  24. cin>>n>>k;
  25. for(int i=1;i<=n;i++){
  26. int a,b;
  27. cin>>a>>b;
  28. A[i].first=a;A[i].second=b;
  29. }
  30. sort(A+1,A+n+1,compareValue);
  31. multiset<int> time;
  32. for(int i=0;i<k;i++){
  33. time.insert(-1);
  34. }
  35.  
  36. for(int i=1;i<=n;i++){
  37. auto it=time.lower_bound(A[i].first);
  38. if(it==time.begin()) continue;
  39. it--; ans++;
  40. time.erase(it);time.insert(A[i].second);
  41.  
  42. }
  43. cout<<ans;
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty