Advertisement
Ahmed_Negm

Untitled

Apr 4th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8. #include<utility>
  9.  
  10. #define ll long long
  11. #define sz(x) int(x.size())
  12. #define all(x) x.begin(),x.end()
  13. using namespace std;
  14.  
  15. void Fast_IO(){
  16.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  17.     #ifndef ONLINE_JUDGE
  18.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  19.     #endif
  20. }
  21.  
  22.  bool compare(pair<ll,ll>& a,pair<ll,ll>& b){
  23.      if(a.first==b.first)
  24.      return a.second>b.second;
  25.      return a.first<b.first;
  26.  }
  27.  bool comp(pair<ll,ll>& a,pair<ll,ll>& b){
  28.      if(a.second==b.second) return a.first<b.first;
  29.      return a.second>b.second;
  30.  }
  31.  
  32.  
  33.  
  34. void solve(){
  35.  
  36. ll n; cin>>n;
  37. pair<ll,ll>p[n];
  38. for(int i =0; i<n; i++){
  39.     cin>>p[i].first>>p[i].second;
  40. }
  41. sort(p,p+n,compare);
  42. sort(p+1,p+n,comp);
  43. if(p[0].first<=p[1].first && p[0].second>=p[1].second){
  44.     cout<<1;
  45. }else if(p[1].first <= p[0].second){
  46.     cout<<"2";
  47. }else{
  48. ll counter =0;
  49. for(int i =2; i<n;i++){
  50.     if(p[i].second<=p[0].second || p[i].first>= p[1].first) counter++;
  51. }
  52. cout<<n-counter;
  53.  
  54.  
  55. }
  56.  
  57. // for(int i=0; i<n; i++){
  58. //     cout<<p[i].first<<' '<<p[i].second<<endl;
  59. // }
  60.  
  61.  
  62.  
  63. }
  64.  
  65. int main(){
  66.     Fast_IO();
  67. int t =1;
  68. //cin>>t;
  69. while(t--){
  70. solve();
  71. }
  72. return 0;
  73. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement