Language: C++

//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<ll, ll> P;

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}

template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int main() {
	int n;
	cin >> n;
	ll L = 0, R = INT_MAX, l = INT_MAX, r = 0;
	vector<P> da(n);
	rip(i, n, 0) {
		cin >> da[i].first >> da[i].second;
		da[i].second++;
		L = max(da[i].first, L);
		R = min(da[i].second, R);
		r = max(da[i].second, r);
		l = max(da[i].first, l);
	}
	ll ans = 0,c = -1;
	rip(i, n, 0) {
        if(ans < da[i].second - da[i].first){
            ans = da[i].second -da[i].first;
            c = i;
        }
	}
    rip(i,n,0){
        if(i!=c){
            r = min(da[i].second,r);
            l = max(da[i].first, l);
        }
    }
    ans += max(r-l,(ll)0);
	vector<P> rl(n * 2);
	rip(i, n, 0) {
		rl[i * 2].first = max(da[i].second - L, (ll)0);
		rl[i * 2 + 1].first = max(R - da[i].first, (ll)0);
		rl[i * 2].second = i + 1;
		rl[i * 2 + 1].second = -i - 1;
	}
	sort(all(rl));
	if (rl[n * 2 - 1].second + rl[n * 2 - 2].second == 0) {
		cout << R - L + da[rl[n * 2 - 1].second - 1].second - da[rl[n * 2 - 1].second - 1].first << endl;
		//cout << 0 << endl;
		return 0;
	}
	priority_queue<pair<P,int>, vector<pair<P, int>>, greater<pair<P, int>>> pq;
	rip(i, n * 2, 0) {
		if (rl[i].second > 0) {
			pq.push(mp(mp(rl[i].first,R - da[rl[i].second-1].first),rl[i].second));
		}
	}
	int nn = R - da[pq.top().second - 1].first;
	pq.pop();
	while (!pq.empty()) {
		ans = max(ans, nn + pq.top().first.first);
		nn = min(nn, R - da[pq.top().second - 1].first);
		pq.pop();
		//cout << ans << endl;
	}
	/*rip(i,n*2,0){
		printf("%d %d\n",rl[i].first,rl[i].second);
	}*/
	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:90:25: error: no matching function for call to 'min(int&, ll)'
   90 |                 nn = min(nn, R - da[pq.top().second - 1].first);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:2:
/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:90:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   90 |                 nn = min(nn, R - da[pq.top().second - 1].first);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/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:90:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   90 |                 nn = min(nn, R - da[pq.top().second - 1].first);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~