YEZAELP

CUBE-026: บริษัททุเรียน (Durian Company)_line sweep

Jun 23rd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using pii=pair<int,int>;
  4. int main(){
  5.  
  6.     int n;
  7.     scanf("%d",&n);
  8.     vector <pii> g;
  9.     for(int i=1;i<=n;i++){
  10.         int u,v;
  11.         scanf("%d%d",&u,&v);
  12.         g.push_back({v,1});//remove
  13.         g.push_back({u,2});//add
  14.     }
  15.     sort(g.begin(),g.end());
  16.     int cnt=0,mx=0;
  17.     for(auto i:g){
  18.         if(i.second==1){
  19.             cnt--;
  20.             mx=max(mx,cnt);
  21.         }
  22.         else {
  23.             cnt++;
  24.             mx=max(mx,cnt);
  25.         }
  26.     }
  27.     printf("%d",mx);
  28.  
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment