Advertisement
tepyotin2

Movie Festival II

Jun 2nd, 2025
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Movie{
  6.     int start, end;
  7.     bool operator<(const Movie &a) const{
  8.         if(end == a.end){
  9.             return start<a.start;
  10.         }
  11.         return end<a.end;
  12.     }
  13. };
  14.  
  15. int n, k;
  16. vector<Movie> mv;
  17. multiset<int, greater<int>> person;
  18. int ans;
  19.  
  20. int main(){
  21.     //freopen("moviefestivalII.in", "r", stdin);
  22.    
  23.     cin >> n >> k;
  24.     //mv.resize(n+1);
  25.     for(int i=0; i<n; i++){
  26.         int a, b;
  27.         cin >> a >> b;
  28.         mv.push_back({a, b});
  29.     }
  30.     sort(mv.begin(), mv.end());
  31.     for(int i=0; i<k; i++){
  32.         person.insert(0);
  33.     }
  34.     for(Movie m: mv){
  35.         auto it = person.lower_bound(m.start);
  36.         if(it == person.end()){
  37.             continue;
  38.         }
  39.         person.erase(it);
  40.         person.insert(m.end);
  41.         ans++;
  42.     }
  43.     cout << ans << '\n';
  44.    
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement