Language: C++

#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
const int MAX=1e9;

int main(){
  long long n, r[100009], l[100009], mx = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> l[i] >> r[i];
  }
  int g1l=l[0], g1r=r[0], g2l=l[1], g2r=r[1];
  for(int i=2;i<n;i++){
    long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
    long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
    long long int tmp3 = max(min(g1r, g2r) - max(g1l, g2l) + 1, 0) + r[i] - l[i] + 1;
    if(tmp1 >= tmp3 && tmp1 >= tmp2){
      g1r = min(g1r, r[i]);g1l = max(l[i], g1l);
    }
    else if(tmp2 >= tmp1 && tmp2 >= tmp3){
      g2r = min(g2r, r[i]);g2l = max(l[i], g2l);
    }
    else{
      g1r = min(g1r, g2r); g1l = max(g1l, g2l);
      g2r = r[i]; g2l = l[i];
    }
  }
  mx = max(mx,max(g1r - g1l + g2r - g2l +2, 0));
  cout << mx << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:33: error: no matching function for call to 'min(int&, long long int&)'
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                              ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:20:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                              ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:20:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                              ~~~^~~~~~~~~~~
a.cc:20:50: error: no matching function for call to 'max(long long int&, int&)'
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                                               ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:20:50: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                                               ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:20:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   20 |     long long int tmp1 = max(min(g1r, r[i]) - max(l[i], g1l) + 1, 0) + g2r - g2l+1;
      |                                               ~~~^~~~~~~~~~~
a.cc:21:33: error: no matching function for call to 'min(int&, long long int&)'
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                              ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:21:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                              ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:21:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                              ~~~^~~~~~~~~~~
a.cc:21:50: error: no matching function for call to 'max(long long int&, int&)'
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                                               ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:21:50: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                                               ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:21:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |     long long int tmp2 = max(min(g2r, r[i]) - max(l[i], g2l) + 1, 0) + g1r - g1l+1;
      |                                               ~~~^~~~~~~~~~~
a.cc:24:16: error: no matching function for call to 'min(int&, long long int&)'
   24 |       g1r = min(g1r, r[i]);g1l = max(l[i], g1l);
      |             ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:24:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   24 |       g1r = min(g1r, r[i]);g1l = max(l[i], g1l);
      |             ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:24:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   24 |       g1r = min(g1r, r[i]);g1l = max(l[i], g1l);
      |             ~~~^~~~~~~~~~~
a.cc:24:37: error: n