Language: C++

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;













#define int long long
const int INF = 1e18;
signed main(){
    int n;
    cin >> n;
    vector<pair<int,int> > a(n);
    int maxxe = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i].fi >> a[i].se;
        maxxe = max(maxxe, a[i].se - a[i].fi + 1);
    }
    int id, maxx = INF;
    for (int i = 0; i < n; i++){
        if (a[i].se < maxx){
            maxx = a[i].se;
            id = i;
        }
    }
    int id2, minx = -INF;
    for (int i = 0; i < n; i++){
        if (a[i].fi > minx){
            minx = a[i].fi;
            id2 = i;
        }
    }
    if (id2 == id){
        cout << maxxe + a[id].se - a[id].fi + 1;
        return 0;
    }
    int len1 = a[id].se - a[id].fi + 1;
    int len2 = a[id2].se - a[id2].fi + 1;
    vector<pair<int,int> > b(n);
    for (int i = 0; i < n; i++){
        int L1 = max(0, min(len1, maxx - a[i].fi + 1));
        int L2 = max(0, min(len2, a[i].se - minx + 1));
        b[i] = {L1, L2};
    }
   // cout << endl;
    //for (auto x : b){
      //  cout << x.fi << ' ' << x.se << endl;
   // }
    //cout << endl;
    map<int,int> x;
    for (int i = 0; i < n; i++) x[b[i].fi]++;
    int c[n];
    int t = 0;
    for (auto y : x){
        c[t] = y.fi;
        t++;
        x[y.fi] = t - 1;
    }
    int ro[n];
    for (int i = 0; i < n; i++) ro[i] = INF;
    for (int i = 0; i < n; i++){
        ro[x[b[i].fi]] = min(ro[x[b[i].fi]], b[i].se);
    }
    int ans = 0;
    int ko = INF;
    for (int i = 0; i < n; i++){
        if (c[i] != 0 && ro[i] != 0 && ko != INF){
            ans = max(ans, c[i] + ko);
        }
        ko = min(ko, ro[i]);
    }
    cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:21: error: no matching function for call to 'max(int, const long long int&)'
   73 |         int L1 = max(0, min(len1, maxx - a[i].fi + 1));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:10:
/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:73:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   73 |         int L1 = max(0, min(len1, maxx - a[i].fi + 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
In file included from /usr/include/c++/14/algorithm:61:
/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:73:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   73 |         int L1 = max(0, min(len1, maxx - a[i].fi + 1));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:74:21: error: no matching function for call to 'max(int, const long long int&)'
   74 |         int L2 = max(0, min(len2, a[i].se - minx + 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:74:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   74 |         int L2 = max(0, min(len2, a[i].se - minx + 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:74:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   74 |         int L2 = max(0, min(len2, a[i].se - minx + 1));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~