Language: C++

    //For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll tree[5000000];

    void build(int node,int l,int r)
    {
        if(l==r)
        {
            tree[node]=0;   //Change for min/sum
            return;
        }
        build(node*2,l,(l+r)/2);
        build(node*2+1,(l+r)/2+1,r);
        tree[node]=max(tree[node*2],tree[node*2+1]);    //Change for min/sum
    }

    void update(int node,int l,int r,int i,ll x)
    {
        if(i<l || r<i)
            return;
        if(l==r)
        {
            tree[node]=x;
            return;
        }
        update(node*2,l,(l+r)/2,i,x);
        update(node*2+1,(l+r)/2+1,r,i,x);
        tree[node]=max(tree[node*2],tree[node*2+1]);    //Change for min/sum
    }
    
    ll query(int node,int l,int r,int i,int j)
    {
        if(j<l || r<i)
            return 0;   //Change for min/sum
        if(i<=l && r<=j)
        {
            return tree[node];
        }
        ll q1=query(node*2,l,(l+r)/2,i,j);
        ll q2=query(node*2+1,(l+r)/2+1,r,i,j);
        return max(q1,q2);  //Change for min/sum
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,x,k,z;
            cin>>n>>k;
            int ar[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            build(1,0,300000);
            for(i=1;i<=n;++i)
            {
                x=query(1,0,300000,max(0,x-k),min(300000,x+k));
                update(1,0,300000,ar[i],x+1);
            }
            x=query(1,0,300000,0,300000);
            cout<<x<<endl;
        }
        return 0;
    }


Compiler output:
a.cc: In function 'int main()':
a.cc:88:39: error: no matching function for call to 'max(int, long long int)'
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                    ~~~^~~~~~~
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:88:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                    ~~~^~~~~~~
/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:88:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                    ~~~^~~~~~~
a.cc:88:50: error: no matching function for call to 'min(int, long long int)'
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                               ~~~^~~~~~~~~~~~
/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:88:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                               ~~~^~~~~~~~~~~~
/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
/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:88:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   88 |                 x=query(1,0,300000,max(0,x-k),min(300000,x+k));
      |                                               ~~~^~~~~~~~~~~~