Advertisement
TOFSIR_IU

Movie Festival

Apr 20th, 2025
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl "\n"
  4. struct structure{
  5.     int start;
  6.     int end;
  7. };
  8. bool comparison(structure a, structure b)
  9. {
  10.     if(a.end<=b.end)
  11.     return true;
  12.     else
  13.     return false;
  14. }
  15. int main()
  16. {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(NULL);
  19.     cout.tie(NULL);
  20.  
  21.     int n;
  22.     cin>>n;
  23.     vector<structure>movies(n);
  24.    
  25.     int a,b;
  26.     for(int i=0;i<n;i++)
  27.     {
  28.         cin>>a>>b;
  29.         movies[i].start=a;
  30.         movies[i].end=b;
  31.     }
  32.     int total=1;
  33.     sort(movies.begin(),movies.end(),comparison);
  34. //  cout<<endl<<endl;
  35. //  for(int i=0;i<n-1;i++)
  36. //  {
  37. //      cout<<movies[i].start<<" "<<movies[i].end<<endl;
  38. //  }
  39.     int cmpValue=movies[0].end;
  40.     for(int i=1;i<n;i++)
  41.     {
  42.         if(movies[i].start>=cmpValue)
  43.         {
  44.             total++;
  45.             cmpValue=movies[i].end;
  46.         }
  47.         //total++;
  48.     }
  49.     cout<<total<<endl;
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement