Language: C++

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N1 100001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountll(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;


mi compress;
struct data
{
    //Use required attributes
    int mn;

    //Default Values
    data() : mn(6*1e9) {};
};

    int N;
    vector<data> st[2];
    vector<bool> cLazy;
    vector<int> lazy;

    void init(int n)
    {
        N = n;
        for(int i=0;i<2;i++)
        st[i].resize(4 * N + 5);
        cLazy.assign(4 * N + 5, false);
        lazy.assign(4 * N + 5, 0);
    }

    //Write reqd merge functions
    void merge(data &cur, data &l, data &r)
    {
        cur.mn = min(l.mn, r.mn);
    }

    //Handle lazy propagation appriopriately
    void build(int node, int L, int R)
    {
        if(L==R)
        {
            st[0][node].mn = 6*1e9;
            st[1][node].mn = 6*1e9;
            return;
        }
        int M=(L + R)/2;
        build(node*2, L, M);
        build(node*2 + 1, M + 1, R);
        for(int i=0;i<2;i++)
        merge(st[i][node], st[i][node*2], st[i][node*2+1]);
    }

    data Query(int node, int L, int R, int i, int j,int id)
    {

        if(j<L || i>R)
            return data();
        if(i<=L && R<=j)
            return st[id][node];
        int M = (L + R)/2;
        data left=Query(node*2, L, M, i, j,id);
        data right=Query(node*2 + 1, M + 1, R, i, j,id);
        data cur;
        merge(cur, left, right);
        return cur;
    }
    void pUpdate(int node, int L, int R, int pos, int val,int id)
    {
        if(L == R)
        {
            //if(st[id][node].mn>val)

            st[id][node].mn=min(st[id][node].mn,val);
            return;
        }
        int M = (L + R)/2;
        if(pos <= M)
            pUpdate(node*2, L, M, pos, val,id);
        else
            pUpdate(node*2 + 1, M + 1, R, pos, val,id);
        for(int i=0;i<2;i++)
        merge(st[i][node], st[i][node*2], st[i][node*2 + 1]);
    }




main()
{
  ios

//si(test);
int test=1,i,j,k,l;
int n,m;
//si(test);
//sieve();
while(test--)
{
  // sii(n,k);
 si(n);
 vii v1;
 set<int>s1;
 for(i=0;i<n;i++)
 {
    int x,y;
    cin>>x>>y;
    v1.pb({x,y});
    s1.insert(x);
    s1.insert(y);
 }
k=2;
for(auto x:s1)
{
    compress[x]=k;
    k++;
}
init(k+2);
sort(all(v1));
int ans=0;
build(1,1,k+1);
for(auto x:v1)
{
    int x1=x.f,y1=x.s;
    data p1=Query(1,1,k+1,1,compress[y1],0);
    data p2=Query(1,1,k+1,compress[y1],k+1,1);
    ans=max(ans,x1+y1-(min(p1.mn,p2.mn)));
    pUpdate(1,1,k+1,y1,x1+y1,0);
    pUpdate(1,1,k+1,y1,x1+y1,1);
}
cout<<ans;
 }
}


Compiler output:
a.cc:41:16: error: template argument 1 is invalid
   41 |     vector<data> st[2];
      |                ^
a.cc:41:16: error: template argument 2 is invalid
a.cc: In function 'void init(long long int)':
a.cc:49:15: error: request for member 'resize' in 'st[i]', which is of non-class type 'int'
   49 |         st[i].resize(4 * N + 5);
      |               ^~~~~~
a.cc: At global scope:
a.cc:55:10: error: variable or field 'merge' declared void
   55 |     void merge(data &cur, data &l, data &r)
      |          ^~~~~
a.cc:55:16: error: reference to 'data' is ambiguous
   55 |     void merge(data &cur, data &l, data &r)
      |                ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data
      |        ^~~~
a.cc:55:22: error: 'cur' was not declared in this scope
   55 |     void merge(data &cur, data &l, data &r)
      |                      ^~~
a.cc:55:27: error: reference to 'data' is ambiguous
   55 |     void merge(data &cur, data &l, data &r)
      |                           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data
      |        ^~~~
a.cc:55:33: error: 'l' was not declared in this scope
   55 |     void merge(data &cur, data &l, data &r)
      |                                 ^
a.cc:55:36: error: reference to 'data' is ambiguous
   55 |     void merge(data &cur, data &l, data &r)
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data
      |        ^~~~
a.cc:55:42: error: 'r' was not declared in this scope
   55 |     void merge(data &cur, data &l, data &r)
      |                                          ^
a.cc: In function 'void build(long long int, long long int, long long int)':
a.cc:65:18: error: invalid types 'int[long long int]' for array subscript
   65 |             st[0][node].mn = 6*1e9;
      |                  ^
a.cc:66:18: error: invalid types 'int[long long int]' for array subscript
   66 |             st[1][node].mn = 6*1e9;
      |                  ^
a.cc:73:20: error: invalid types 'int[long long int]' for array subscript
   73 |         merge(st[i][node], st[i][node*2], st[i][node*2+1]);
      |                    ^
a.cc:73:33: error: invalid types 'int[long long int]' for array subscript
   73 |         merge(st[i][node], st[i][node*2], st[i][node*2+1]);
      |                                 ^
a.cc:73:48: error: invalid types 'int[long long int]' for array subscript
   73 |         merge(st[i][node], st[i][node*2], st[i][node*2+1]);
      |                                                ^
a.cc: At global scope:
a.cc:76:5: error: reference to 'data' is ambiguous
   76 |     data Query(int node, int L, int R, int i, int j,int id)
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data
      |        ^~~~
a.cc: In function 'void pUpdate(long long int, long long int, long long int, long long int, long long int, long long int)':
a.cc:96:19: error: invalid types 'int[long long int]' for array subscript
   96 |             st[id][node].mn=min(st[id][node].mn,val);
      |                   ^
a.cc:96:39: error: invalid types 'int[long long int]' for array subscript
   96 |             st[id][node].mn=min(st[id][node].mn,val);
      |                                       ^
a.cc:105:20: error: invalid types 'int[long long int]' for array subscript
  105 |         merge(st[i][node], st[i][node*2], st[i][node*2 + 1]);
      |                    ^
a.cc:105:33: error: invalid types 'int[long long int]' for array subscript
  105 |         merge(st[i][node], st[i][node*2], st[i][node*2 + 1]);
      |                                 ^
a.cc:105:48: error: invalid types 'int[long long int]' for array subscript
  105 |         merge(st[i][node], st[i][node*2], st[i][node*2 + 1]);
      |                                                ^
a.cc: At global scope:
a.cc:111:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  111 | main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:147:5: error: reference to 'data' is ambiguous
  147 |     data p1=Query(1,1,k+1,1,compress[y1],0);
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data
      |        ^~~~
a.cc:148:5: error: reference to 'data' is ambiguous
  148 |     data p2=Query(1,1,k+1,compress[y1],k+1,1);
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:31:8: note:                 'struct data'
   31 | struct data