Language: C++

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=100005;
//const ll Mod=1000000007;
using namespace std;

ll n,L[maxn],R[maxn],id[maxn],zxr,pr,pl,zdl;

bool cmp(int a,int b)
{
    if(R[a]==R[b])
        return L[a]<L[b];
    return R[a]<R[b];
}

ll d(int l,int r)
{
    return 1ll*max(0,r-l+1);
}

int main()
{
    sync;
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&L[i],&R[i]);
    zxr=2e16;
    zdl=0;
    for(int i=1;i<=n;i++)
    {
        if(R[i]<zxr)
        {
            zxr=R[pr=i];
        }
        if(L[i]>zdl)
        {
            zdl=L[pl=i];
        }
    }
    
    ll ans=0;
    
    for(int i=1;i<=n;i++)
    {
        if(i!=pl&&i!=pr)
        {
            ans=max(ans,d(zdl,zxr)+d(L[i],R[i]));
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        id[i]=i;
    }
    sort(id+1,id+n+1,cmp);
    int p=0;
    for(int i=2;i<=n;i++)
    {
        p=max(p,L[id[i-1]]);
        ans=max(ans,d(zdl,R[id[i]])+d(p,zxr));
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:85:14: error: no matching function for call to 'max(int&, ll&)'
   85 |         p=max(p,L[id[i-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: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:85:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   85 |         p=max(p,L[id[i-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,
                 from a.cc:5:
/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:85:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |         p=max(p,L[id[i-1]]);
      |           ~~~^~~~~~~~~~~~~~