Language: C++

#include <iostream>
#include <map>
using namespace std;
int N;
map <pair <int, int>, int> M;
pair <int, int> Array[200005];
pair <int, int> PMax, PMin;
vector <pair <int, pair <int, int> > > V;
int Max = -1, Min = 1000000005;
int P[800005];
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
    {
        cin >> Array[i].first >> Array[i].second;
        if(Max < Array[i].first)
        {
            Max = Array[i].first;
            PMax = make_pair(i, 1);
        }
        if(Min > Array[i].first)
        {
            Min = Array[i].first;
            PMin = make_pair(i, 1);
        }
        if(Max < Array[i].second)
        {
            Max = Array[i].second;
            PMax = make_pair(i, 2);
        }
        if(Min > Array[i].second)
        {
            Min = Array[i].second;
            PMin = make_pair(i, 2);
        }
    }
}

long long Solve1()
{
    int RMax = -1, BMin = 1000000005;
    for(int i = 1; i <= N; i++)
    {
        int a = Array[i].first, b = Array[i].second;
        if(a > b)
            swap(a, b);
        RMax = max(RMax, a);
        BMin = min(BMin, b);
    }
    return 1LL * (Max - BMin) * (RMax - Min);
}
int Pair(int pos)
{
    int x = V[pos].second.first;
    if(V[pos].second.second == 1)
        return M[make_pair(x, 2)];
    return M[make_pair(x, 1)];
}
long long Solve2()
{
    M[PMin] = M[PMax] = 4 * N;
    for(int i = 1; i <= N; i++)
    {

        if(PMin != make_pair(i, 1) && PMax != make_pair(i, 1))
            V.push_back(make_pair(Array[i].first, make_pair(i, 1)));
        if(PMin != make_pair(i, 2) && PMax != make_pair(i, 2))
            V.push_back(make_pair(Array[i].second, make_pair(i, 2)));
    }
    sort(V.begin(), V.end());
    for(int i = 0; i < V.size(); i++)
        M[V.second] = i;
    int stop = 4 * N;
    for(int i = 0; i < V.size(); i++)
    {
        stop = min(stop, Pair(i));
        if(i > 0)
            P[i] = min(P[i - 1], stop);
        else
            P[i] = stop;
    }
    int cnt = 0, stop2 = -1, val = -1;
    long long ans = 0, point = 4 * N;
    while(cnt <= N)
    {
        if(V.size() - 1 - cnt < stop2)
            break;
        if(cnt < N)
            point = min(P[N - cnt - 1], point);
        point = min(point, Pair(V.size() - 1 - cnt));
        point = min(point, N - cnt);
        val = V[V.size() - 1 - cnt];
        ans = max(ans, (val - V[point]));
        stop2 = max(stop2, Pair(V.size() - 1 - cnt));
        ++cnt;
    }
    return ans * (Max - Min);
}
int main()
{
    Read();
    long long ans = Solve1();
    if(PMin.first != PMin.second)
        ans = min(ans, Solve2());
    cout << ans << '\n';
    return 0;
}


Compiler output:
a.cc:8:1: error: 'vector' does not name a type
    8 | vector <pair <int, pair <int, int> > > V;
      | ^~~~~~
a.cc: In function 'int Pair(int)':
a.cc:55:13: error: 'V' was not declared in this scope
   55 |     int x = V[pos].second.first;
      |             ^
a.cc: In function 'long long int Solve2()':
a.cc:67:13: error: 'V' was not declared in this scope
   67 |             V.push_back(make_pair(Array[i].first, make_pair(i, 1)));
      |             ^
a.cc:69:13: error: 'V' was not declared in this scope
   69 |             V.push_back(make_pair(Array[i].second, make_pair(i, 2)));
      |             ^
a.cc:71:10: error: 'V' was not declared in this scope
   71 |     sort(V.begin(), V.end());
      |          ^
a.cc:71:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   71 |     sort(V.begin(), V.end());
      |     ^~~~
      |     short
a.cc:90:24: error: no matching function for call to 'min(int&, long long int&)'
   90 |             point = min(P[N - cnt - 1], point);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~
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: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:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   90 |             point = min(P[N - cnt - 1], point);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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
a.cc:92:20: error: no matching function for call to 'min(long long int&, int)'
   92 |         point = min(point, N - cnt);
      |                 ~~~^~~~~~~~~~~~~~~~
/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:92:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   92 |         point = min(point, N - cnt);
      |                 ~~~^~~~~~~~~~~~~~~~
/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