Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
struct node
{
	int l,r;
}e[maxn];
bool cmp(node a,node b)
{
	return a.l<b.l;
}

int main()
{
	int n,p,q,lmax=0,rmin=0x3f3f3f3f;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&e[i].l,&e[i].r);
		if(lmax<e[i].l) lmax=e[i].l,p=i;
		if(rmin>e[i].r) rmin=e[i].r,q=i;
	}
		
	sort(e,e+n,cmp);
	ll lx[maxn],rx[maxn];
	lx[0]=e[0].l,rx[0]=e[0].r;
	for(int i=1;i<n;i++)
	{
		lx[i]=max(lx[i-1],e[i].l);
		rx[i]=min(rx[i-1],e[i].r);
	}
	ll ly[maxn],ry[maxn];
	ly[n-1]=e[n-1].l,ry[n-1]=e[n-1].r;
	for(int i=n-2;i>=0;i--)
	{
		ly[i]=max(ly[i+1],e[i].l);
		ry[i]=min(ry[i+1],e[i].r);
	}
	ll ans1=max(0,rmin-lmax+1),ans2=0;
	for(int i=1;i<n-1;i++)
		//if(i!=q&&i!=p)
		ans1=max(ans1,max(e[i].r-e[i].l+1,min(ry[i+1],rx[i-1])-min(lx[i-1],ly[i+1])+1));
	for(int i=0;i<n-1;i++)
	{
		ans2=max(ans2,max(0,rx[i]-lx[i]+1)+max(ry[i+1]-ly[i+1]+1,0));
	}
//	cout<<ans1<<' '<<ans2<<endl;
	cout<<max(ans1,ans2)<<endl;
	return 0;
 } 

Compiler output:
a.cc: In function 'int main()':
a.cc:30:26: error: no matching function for call to 'max(ll&, int&)'
   30 |                 lx[i]=max(lx[i-1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
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: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:30:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |                 lx[i]=max(lx[i-1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:30:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |                 lx[i]=max(lx[i-1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
a.cc:31:26: error: no matching function for call to 'min(ll&, int&)'
   31 |                 rx[i]=min(rx[i-1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:31:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |                 rx[i]=min(rx[i-1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:31:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |                 rx[i]=min(rx[i-1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
a.cc:37:26: error: no matching function for call to 'max(ll&, int&)'
   37 |                 ly[i]=max(ly[i+1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:37:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   37 |                 ly[i]=max(ly[i+1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:37:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |                 ly[i]=max(ly[i+1],e[i].l);
      |                       ~~~^~~~~~~~~~~~~~~~
a.cc:38:26: error: no matching function for call to 'min(ll&, int&)'
   38 |                 ry[i]=min(ry[i+1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:38:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |                 ry[i]=min(ry[i+1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
/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:38:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   38 |                 ry[i]=min(ry[i+1],e[i].r);
      |                       ~~~^~~~~~~~~~~~~~~~
a.cc:43:34: error: no matching function for call to 'max(int, long long int)'
   43 |                 ans1=max(ans1,max(e[i].r-e[i].l+1,min(ry[i+1],rx[i-1])-min(lx[i-1],ly[i+1])+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:43:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   43 |                 ans1=max(ans1,max(e[i].r-e[i].l+1,min(ry[i+1],rx[i-1])-min(lx[i-1],ly[i+1])+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:43:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   43 |                 ans1=max(ans1,max(e[i].r-e[i].l+1,min(ry[i+1],rx[i-1])-min(lx[i-1],ly[i+1])+1));
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:34: error: no matching function for call to 'max(int, ll)'
   46 |                 ans2=max(ans2,max(0,rx[i]-lx[i]+1)+max(ry[i+1]-ly[i+1]+1,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:46:34: note:   deduced conflic