Language: C++


#include "bits/stdc++.h"
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<pair<int64_t, int>> R(0);
	vector<int64_t> L(0);
	for (int i = 0; i < N; i++)
	{
		int64_t r, l;
		cin >> l >> r;
		L.push_back(l);
		R.push_back(pair<int64_t, int>(r, i));
	}
	//sort(L.begin(), L.end());
	sort(R.begin(), R.end());

	//ilu[n]はR[n]までを一方に入れたときのありうるLの一番大きい(範囲が狭くなる)値
	vector<int64_t> ilu(N);
	ilu[0] = L[R[0].second];
	for (int i = 1; i < N; i++)
	{
		ilu[i] = max(ilu[i - 1], L[R[i].second]);
	}
	//iln[n]はR[n]までを一方に入れたときの残りのLの一番大きい(範囲が狭くなる)値
	vector<int64_t> iln(N - 2);
	if (N >= 3)
		iln[N - 3] = L[R[N - 1].second];
	for (int i = N - 4; i >= 0; i--)
	{
		iln[i] = max(iln[i + 1], L[R[i + 2].second]);
	}
	//vector<int64_t> fun(N);
	int64_t fun = 0;
	for (int i = 0; i < N - 1; i++)
	{
		int64_t f;
		if (i == N - 2) {
			f = max(R[0].first - ilu[i]+1,0ll) + R[i + 1].first - L[R[i + 1].second]+1;
		}
		else if (ilu[i] >= L[R[i + 1].second])
		{
			f = max(R[0].first - max(iln[i], ilu[i])+1,0ll) + (R[i + 1].first - L[R[i + 1].second]+1);
		}
		else {
			f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
		}
		fun = max(fun, f );
	}
	cout << fun;
	return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:42:32: error: no matching function for call to 'max(long int, long long int)'
   42 |                         f = max(R[0].first - ilu[i]+1,0ll) + R[i + 1].first - L[R[i + 1].second]+1;
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:42:32: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   42 |                         f = max(R[0].first - ilu[i]+1,0ll) + R[i + 1].first - L[R[i + 1].second]+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:
/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:42:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   42 |                         f = max(R[0].first - ilu[i]+1,0ll) + R[i + 1].first - L[R[i + 1].second]+1;
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:32: error: no matching function for call to 'max(long int, long long int)'
   46 |                         f = max(R[0].first - max(iln[i], ilu[i])+1,0ll) + (R[i + 1].first - L[R[i + 1].second]+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:46:32: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   46 |                         f = max(R[0].first - max(iln[i], ilu[i])+1,0ll) + (R[i + 1].first - L[R[i + 1].second]+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:46:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   46 |                         f = max(R[0].first - max(iln[i], ilu[i])+1,0ll) + (R[i + 1].first - L[R[i + 1].second]+1);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:32: error: no matching function for call to 'max(long int, long long int)'
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:49:32: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:49:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:65: error: no matching function for call to 'max(long int, long long int)'
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:49:65: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:49:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   49 |                         f = max(R[0].first - ilu[i]+1,0ll) + max(R[i + 1].first - max(iln[i], L[R[i + 1].second])+1,0ll);
      |                                                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~