Language: C++

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 5005;

struct data
{
	int h, p;
};

int n, mx;
data a[N];
int cache[N][N];

bool comp(data &d1, data &d2)
{
	return d1.h + d1.p < d2.h + d2.p;
}

int dp(int i, int taken) //should store minP sum
{
	if(i == 0)
	{
		if(taken == 0)
			return 0;
		return 1e14;
	}
	int &ans = cache[i][taken];
	if(ans != -1)
		return ans;
	ans = dp(i - 1, taken);
	int curSum = dp(i - 1, taken - 1);
	if(a[i].h >= curSum)
		ans = min(ans, dp(i - 1, taken - 1) + a[i].p);
	//cerr << i << " " << taken << " " << ans << endl;
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i].h >> a[i].p;
	sort(a + 1, a + n + 1, comp);
	for(int i = n; i >= 1; i--)
	{
		if(dp(n, i) < 1e14)
		{
			cout << i;
			return 0;
		}
	}
	return 0;
}

Compiler output:
a.cc:16:1: error: reference to 'data' is ambiguous
   16 | data a[N];
      | ^~~~
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:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc:19:11: error: reference to 'data' is ambiguous
   19 | bool comp(data &d1, data &d2)
      |           ^~~~
/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:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc:19:17: error: 'd1' was not declared in this scope; did you mean 'y1'?
   19 | bool comp(data &d1, data &d2)
      |                 ^~
      |                 y1
a.cc:19:21: error: reference to 'data' is ambiguous
   19 | bool comp(data &d1, data &d2)
      |                     ^~~~
/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:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc:19:27: error: 'd2' was not declared in this scope
   19 | bool comp(data &d1, data &d2)
      |                           ^~
a.cc:19:29: error: expression list treated as compound expression in initializer [-fpermissive]
   19 | bool comp(data &d1, data &d2)
      |                             ^
a.cc: In function 'long long int dp(long long int, long long int)':
a.cc:37:12: error: 'a' was not declared in this scope
   37 |         if(a[i].h >= curSum)
      |            ^
a.cc: In function 'int32_t main()':
a.cc:49:24: error: 'a' was not declared in this scope
   49 |                 cin >> a[i].h >> a[i].p;
      |                        ^
a.cc:50:14: error: 'a' was not declared in this scope
   50 |         sort(a + 1, a + n + 1, comp);
      |              ^