Language: C++

#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define mp make_pair
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define x first
#define y second

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

const int N=1e5+100;

pii p[N];
int pl[N],pr[N],sl[N],sr[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].x>>p[i].y;
        ans=max(ans,p[i].y-p[i].x+1);
        if(p[i].y<p[1].y||p[i].y==p[1].y&&p[i].x>p[1].x)
            swap(p[i],p[1]);
    }
    sort(p+2,p+n+1);
    pl[0]=-1,pr[0]=1e10;
    for(int i=1;i<=n;i++)
        pl[i]=max(pl[i-1],p[i].x),
        pr[i]=min(pr[i-1],p[i].y);
    sl[n+1]=-1,sr[n+1]=1e10;
    for(int i=n;i>=1;i--)
        sl[i]=max(sl[i+1],p[i].x),
        sr[i]=min(sr[i+1],p[i].y);
    ans+=max(0,pr[n]-pl[n]+1);
    for(int i=1;i<=n-1;i++)
        ans=max(ans,pr[i]-pl[i]+1+sr[i+1]-sl[i+1]+1);
    cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:71:13: error: no matching function for call to 'max(int, ll)'
   71 |     ans+=max(0,pr[n]-pl[n]+1);
      |          ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_uninitialized.h:63,
                 from /usr/include/c++/14/memory:69,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:44,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:47,
                 from a.cc:2:
/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:71:13: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   71 |     ans+=max(0,pr[n]-pl[n]+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 /usr/include/c++/14/ext/pb_ds/hash_policy.hpp:45,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:45:
/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:71:13: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   71 |     ans+=max(0,pr[n]-pl[n]+1);
      |          ~~~^~~~~~~~~~~~~~~~~