Advertisement
Josif_tepe

Untitled

Dec 30th, 2023
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. const long long maxn =1e6+10;
  8. const long long mod=1e9+7;
  9.  
  10. int main()
  11. {
  12.     ///ifstream cin("haircut.in");
  13.     ///ofstream cout("haircut.out");
  14.     ios_base::sync_with_stdio(false); cin.tie(0);
  15.     long long n,k;
  16.     cin>>n>>k;
  17.     vector<pair<long long,long long>>v;
  18.     for(long long i=0;i<n;i++)
  19.     {
  20.         long long x,y;
  21.         cin>>x>>y;
  22.         v.push_back({y,x});
  23.     }
  24.     sort(v.begin(),v.end());
  25.     multiset<long long>ms;
  26.     while(k--)
  27.     {
  28.         ms.insert(0);
  29.     }
  30.     long long ans=0;
  31.     for(long long i=0;i<n;i++)
  32.     {
  33.         multiset<long long>::iterator it = ms.upper_bound(v[i].second);
  34.         if(it == ms.begin()) continue;
  35.         it--;
  36.        
  37.         ms.erase(it);
  38.         ms.insert(v[i].first);
  39.         ans++;
  40.     }
  41.    
  42.     cout<<ans<<endl;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement