josiftepe

Untitled

Oct 24th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.     int
  11.     n;
  12.     int max =
  13.     0;
  14.     cin >> n;
  15.     vector<int> a(n);
  16.     vector<int>b(n);
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         cin >> a[i] >>b[i];
  20.        
  21.    
  22.    
  23.     }
  24.     
    sort(a.begin(),
  25.          a
  26.          .end
  27. ());
  28.     sort(b.begin(),
  29.          b
  30.          .end
  31. ());
  32.     int j =
  33.     0;
  34.     int c =
  35.     0;
  36.  
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         if (a[i] <= b[j])
  40.         {
  41.            
  42.             c++;
  43.            
  44.             

  45.             if (c > max)
  46.             {
  47.                 max =
  48.                 c;
  49.                
  50.                
  51.            
  52.             }
  53.            
  54.         } else
  55.         {
  56.             while (a[i] == b[j])
  57.             {
  58.                
  59.                 c--;
  60.                
  61.                 j++;
  62.                 

  63.                
  64.            
  65.            
  66.             }
  67.             if (a[i] > b[j])
  68.             {
  69.                
  70.                 c--;
  71.                 j++;
  72.                
  73.            
  74.             }
  75.            
  76.             i--;
  77.            
  78.        
  79.         }
  80.        
  81.    
  82.     }
  83.     cout <<   max;
  84.    
  85. }
  86.  
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment