Language: C++

//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
typedef pair<int,int> pi;
int n,res,Pre[N],suf[N],st[N],ins[N],top;pi a[N],L;
inline pi operator +(const pi &a,const pi &b){return pi(b.fi,a.se);}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d%d",&a[i].fi,&a[i].se);
	sort(a+1,a+1+n);
	fp(i,1,n){
		while(top&&a[st[top]].se>=a[i].se)--top;
		st[++top]=i;
	}
	fp(i,1,top)ins[st[i]]=1;
	L=a[st[1]],Pre[1]=L.se-L.fi+1;
	fp(i,2,top){
		L=L+a[st[i]];if(L.se<L.fi)break;
		Pre[i]=L.se-L.fi+1;
	}
	L=a[st[top]],suf[top]=L.se-L.fi+1;
	fd(i,top-1,1){
		L=a[st[i]]+L;if(L.se<L.fi)break;
		suf[i]=L.se-L.fi+1;
	}
	fp(i,1,top-1)cmax(res,Pre[i]+suf[i+1]);
	fp(i,1,n)if(!ins[i])cmax(res,Pre[top]+st[i].se-st[i].fi+1);
	printf("%d\n",res);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |         fp(i,1,n)scanf("%d%d",&a[i].fi,&a[i].se);
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:19:9: note: in expansion of macro 'fp'
   19 |         fp(i,1,n)scanf("%d%d",&a[i].fi,&a[i].se);
      |         ^~
a.cc:21:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         fp(i,1,n){
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:21:9: note: in expansion of macro 'fp'
   21 |         fp(i,1,n){
      |         ^~
a.cc:25:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |         fp(i,1,top)ins[st[i]]=1;
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:25:9: note: in expansion of macro 'fp'
   25 |         fp(i,1,top)ins[st[i]]=1;
      |         ^~
a.cc:27:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |         fp(i,2,top){
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:27:9: note: in expansion of macro 'fp'
   27 |         fp(i,2,top){
      |         ^~
a.cc:32:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         fd(i,top-1,1){
      |            ^
a.cc:7:29: note: in definition of macro 'fd'
    7 | #define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
      |                             ^
a.cc:7:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    7 | #define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
      |                                   ^
a.cc:32:9: note: in expansion of macro 'fd'
   32 |         fd(i,top-1,1){
      |         ^~
a.cc:36:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |         fp(i,1,top-1)cmax(res,Pre[i]+suf[i+1]);
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:36:9: note: in expansion of macro 'fp'
   36 |         fp(i,1,top-1)cmax(res,Pre[i]+suf[i+1]);
      |         ^~
a.cc:37:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         fp(i,1,n)if(!ins[i])cmax(res,Pre[top]+st[i].se-st[i].fi+1);
      |            ^
a.cc:6:29: note: in definition of macro 'fp'
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:6:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:37:9: note: in expansion of macro 'fp'
   37 |         fp(i,1,n)if(!ins[i])cmax(res,Pre[top]+st[i].se-st[i].fi+1);
      |         ^~
a.cc:5:12: error: request for member 'second' in 'st[i]', which is of non-class type 'int'
    5 | #define se second
      |            ^~~~~~
a.cc:37:53: note: in expansion of macro 'se'
   37 |         fp(i,1,n)if(!ins[i])cmax(res,Pre[top]+st[i].se-st[i].fi+1);
      |                                                     ^~
a.cc:4:12: error: request for member 'first' in 'st[i]', which is of non-class type 'int'
    4 | #define fi first
      |            ^~~~~
a.cc:37:62: note: in expansion of macro 'fi'
   37 |         fp(i,1,n)if(!ins[i])cmax(res,Pre[top]+st[i].se-st[i].fi+1);
      |                                                              ^~