Language: C++

// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
struct node
{
    ll a;
};
ll n = N;
vector<node> t(2 * N);
node combine(node l, node r)
{
    node res;
    res.a = max(l.a, r.a);
    return res;
}
void update(int p, node value)
{
    for (t[p += n] = value; p >>= 1;)
        t[p] = combine(t[p << 1], t[p << 1 | 1]);
}
void build()
{
    for (ll i = n - 1; i > 0; --i)
        t[i] = combine(t[i << 1], t[i << 1 | 1]);
}
node query(ll l, ll r)
{
    node resl = {0}, resr = {0};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            resl = combine(resl, t[l++]);
        if (r & 1)
            resr = combine(t[--r], resr);
    }
    return combine(resl, resr);
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e;
    for (ll i = 0; i < n; i++)
    {
        ll l = max(0LL, a[i] - k);
        ll r = a[i] + k;
        ll x = query(l, r + 1).a + 1;
        update(a[i], {x});
    }
    cout << query(0, N).a;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:19: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
   51 |         ll l = max(0LL, a[i] - 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:3:
/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:51:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   51 |         ll l = max(0LL, a[i] - 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:51:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |         ll l = max(0LL, a[i] - k);
      |                ~~~^~~~~~~~~~~~~~~