Language: C++

#include <cstdio>
#include <cmath>
#include <stack>
using namespace std;
int data[300010];
int num[300010];
int grp[300010];
int n;
int k;
void kFlat() {
	num[0] = 1;
	grp[0] = 0;
	for(int i = 1; i < n; i++) {
		int max = 1;
		int g = i;
		for(int j = 0; j < i; j++) {
			if( abs(data[i] - data[j]) <= k ) {
				if ( num[j] >= max) {
					max = num[j] + 1;
					g = j;
				}
			}
		}
		num[i] = max;
		grp[i] = g;
	}
	int maxIndex = 0;
	int maxValue = 0;
	for(int i = 0; i < n; i++) {
		if(num[i] > maxValue) {
			maxValue = num[i];
			maxIndex = i;
		}
	}
	stack<int> s;
	do {
		s.push(data[maxIndex]);
		maxIndex = grp[maxIndex];
		maxValue--;
	} while(maxValue > 0);
	while(!s.empty()) {
		printf("%d ", s.top());
		s.pop();
	}
}
int main() {
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}
	kFlat();
	return 0;
}

Compiler output:
a.cc: In function 'void kFlat()':
a.cc:17:33: error: reference to 'data' is ambiguous
   17 |                         if( abs(data[i] - data[j]) <= k ) {
      |                                 ^~~~
In file included from /usr/include/c++/14/deque:68,
                 from /usr/include/c++/14/stack:62,
                 from a.cc:3:
/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:5:5: note:                 'int data [300010]'
    5 | int data[300010];
      |     ^~~~
a.cc:17:43: error: reference to 'data' is ambiguous
   17 |                         if( abs(data[i] - data[j]) <= k ) {
      |                                           ^~~~
/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:5:5: note:                 'int data [300010]'
    5 | int data[300010];
      |     ^~~~
a.cc:37:24: error: reference to 'data' is ambiguous
   37 |                 s.push(data[maxIndex]);
      |                        ^~~~
/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:5:5: note:                 'int data [300010]'
    5 | int data[300010];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:49:30: error: reference to 'data' is ambiguous
   49 |                 scanf("%d", &data[i]);
      |                              ^~~~
/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:5:5: note:                 'int data [300010]'
    5 | int data[300010];
      |     ^~~~