josiftepe

Untitled

Oct 24th, 2020
79
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 <algorithm>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6.  
  7. struct movie{
  8.     int S, E;
  9.     movie(){}
  10.     movie(int a, int b) {
  11.         S = a;
  12.         E = b;
  13.     }
  14.     bool operator < (const movie &x) const {
  15.         return E < x.E;
  16.     }
  17. };
  18. int main()
  19. {
  20.     ios_base::sync_with_stdio(false);
  21.     int n;
  22.     cin >> n;
  23.     vector<movie> v;
  24.     for(int i =0; i < n; ++i) {
  25.         int a, b;
  26.         cin >> a >> b;
  27.         v.push_back(movie(a, b));
  28.     }
  29.     sort(v.begin(), v.end());
  30.     int last_ending_time = v[0].E;
  31.     int ret = 1;
  32.     for(int i = 1; i < n; ++i) {
  33.         if(last_ending_time <= v[i].S) {
  34.             ++ret;
  35.             last_ending_time = v[i].E;
  36.         }
  37.     }
  38.     cout << ret << endl;
  39.     return 0;
  40. }
  41.  
  42.  
  43.  
  44. /*
  45.  10
  46.  404 882
  47.  690 974
  48.  201 255
  49.  800 933
  50.  525 819
  51.  457 601
  52.  461 978
  53.  832 932
  54.  699 804
  55.  795 860
  56.  */
  57.  
Advertisement
Add Comment
Please, Sign In to add comment