Advertisement
tomalikem

schedule

Jun 7th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstdlib>
  3. #include<iomanip>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct Event {
  9.     int start, end;
  10.     /* bool operator < (const Event &x)const
  11.   {
  12.     return start<x.start;
  13.   } */
  14. };
  15.  
  16.  
  17. int how_many_rooms (Event* e, int N)
  18. {
  19.     // sort(e,e+N);
  20.     int maxr=0,r=0,time;
  21.     int i=0,j=0;
  22.     for(i;i<N;i++)
  23.     {
  24.         time=e[i].start;
  25.         while(e[j].end<=time)
  26.         {
  27.             r--;
  28.             j++;
  29.         }
  30.         r++;
  31.         if(r>maxr)maxr=r;
  32.     }
  33.     return maxr;
  34. }
  35.  
  36. int main() {
  37.     int N;
  38.     cin >> N;
  39.     Event e[N];
  40.     for (int i=0; i<N; i++) cin >> e[i].start >> e[i].end;
  41.  
  42.     cout << how_many_rooms(e, N) << endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement