Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  ll N,ans=0;
  cin>>N;
  
  vector<pair<ll,ll>> L;
  L.push_back(make_pair(0,0));
  
  REP(i,N){
    ll a,b;
    cin>>a>>b;
    L.push_back(make_pair(a,b));
  }
  
  SORT(L);
  
  ll A[N+1],B[N+1],C[N+1],D[N+1];
  REP(i,N+2){
    A[i]=0;
    B[i]=0;
    C[i]=0;
    D[i]=0;
  }
  A[0]=0,B[0]=INF,C[N]=0,D[N]=INF;
  
  for(int i=1; i<N; ++i){
    A[i]=max(A[i-1],L[i].first);
    B[i]=min(B[i-1],L[i].second);
  }
  
  for(int i=N-1; i>1; --i){
    C[i]=max(C[i+1],L[i+1].first);
    D[i]=min(D[i+1],L[i+1].second);
  }
  
  
  
  for(int i=1; i<N; ++i){
    ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
  }
  
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:20: error: no matching function for call to 'max(long long int, int)'
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                 ~~~^~~~~~~~~~~~~
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:68:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                 ~~~^~~~~~~~~~~~~
/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:4:
/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:68:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                 ~~~^~~~~~~~~~~~~
a.cc:68:37: error: no matching function for call to 'max(long long int, int)'
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                                  ~~~^~~~~~~~~~~~~
/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:68:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                                  ~~~^~~~~~~~~~~~~
/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:68:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   68 |     ans=max(ans,max(B[i]-A[i],0)+max(D[i]-C[i],0));
      |                                  ~~~^~~~~~~~~~~~~