SHARE
TWEET

Untitled

a guest May 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct event {
  7.     int time;
  8.     int type;
  9.     // 0 - вход
  10.     // 1 - выход
  11. };
  12.  
  13. // true, если a < b
  14. bool operator < (event a, event b){
  15.     if (a.time < b.time)
  16.         return true;
  17.     if (a.time > b.time)
  18.         return false;
  19.     if (a.time == b.time){
  20.         if (a.type < b.type){
  21.             return true;
  22.         } else {
  23.             return false;
  24.         }
  25.     }
  26.     return false;
  27. }
  28.  
  29.  
  30. int main() {
  31.     int n;
  32.     cin >> n;
  33.     vector <event> events;
  34.     for (int i = 0; i < n; i++){
  35.         int in, out;
  36.         cin >> in >> out;
  37.         event in_event;
  38.         in_event.type = 0;
  39.         in_event.time = in;
  40.         event out_event;
  41.         out_event.type = 1;
  42.         out_event.time = out;
  43.         events.push_back(in_event);
  44.         events.push_back(out_event);
  45.     }
  46.    
  47.     sort(events.begin(), events.end());
  48.     int visitor_count = 0;
  49.     int max_visitor_count = 0;
  50.    
  51.     for (int i = 0; i < events.size(); i++){
  52.         if (events[i].type == 0) {
  53.             visitor_count++;
  54.         } else {
  55.             visitor_count--;
  56.         }
  57.         if ( visitor_count > max_visitor_count ) {
  58.             max_visitor_count = visitor_count;
  59.         }
  60.     }
  61.    
  62.     cout << max_visitor_count << endl;
  63.     return 0;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top