fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int roomsneeded(vector< int > start, vector< int > over, int n)
  5. {
  6. sort(start.begin(), start.end());
  7. sort(over.begin(), over.end());
  8.  
  9. int rooms_needed = 1, result = 1;
  10. int i = 1, j = 0;
  11.  
  12. while (i < n && j < n)
  13. {
  14. if (start[i] < over[j])
  15. {
  16. rooms_needed++;
  17. i++;
  18. if (rooms_needed > result)
  19. result = rooms_needed;
  20. }
  21. else
  22. {
  23. rooms_needed--;
  24. j++;
  25. }
  26. }
  27.  
  28. return result;
  29. }
  30.  
  31. int main()
  32. {
  33. vector< int > start,over;
  34. int noofconf,starttime,endtime;
  35. cin>>noofconf;
  36. for(int i = 0 ; i < noofconf ; i++)
  37. {
  38. cin>>starttime>>endtime;
  39. start.push_back(starttime);
  40. over.push_back(endtime);
  41.  
  42. }
  43. cout << roomsneeded(start, over, noofconf);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 16064KB
stdin
3
1 3
2 4
3 5
stdout
2