Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first  // Weight
#define S second // Cost
// state : index , remaining capacity
// transition : take item i or leave item i
// base case : index=N or capacity =0
const int N=107  ;
pair<ll,ll>tests[N];
ll dp[N][100008];
int size ;

ll Solve(int index, ll rem_capacity)
{
	if (index==size||!rem_capacity)
		 return 0 ;

	if (dp[index][rem_capacity]!=-1)
		return dp[index][rem_capacity] ;

	// leave item i :
	ll ans=Solve(index+1 , rem_capacity) ;

	// Take item i
	if (tests[index].F<=rem_capacity)
	{
		// maximum between take i and leave i
	    ans =max(ans , tests[index].S + Solve( index+1 , (rem_capacity-tests[index].F)) ) ;
	}
	return dp[index][rem_capacity]=ans ;
}
int main() {


	ll Capacity ;
	cin>>size >>Capacity ;

	for (int j=0 ;j<size ;j++)
	{
		ll w,c ;
		cin>>w>>c ;
		tests[j].F=w,tests[j].S=c ;
	}

	memset(dp,-1,sizeof dp) ;
	cout << Solve (0,Capacity);








	return 0;
}


Compiler output:
a.cc: In function 'long long int Solve(int, long long int)':
a.cc:16:20: error: reference to 'size' is ambiguous
   16 |         if (index==size||!rem_capacity)
      |                    ^~~~
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:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size'
   12 | int size ;
      |     ^~~~
a.cc: In function 'int main()':
a.cc:37:14: error: reference to 'size' is ambiguous
   37 |         cin>>size >>Capacity ;
      |              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size'
   12 | int size ;
      |     ^~~~
a.cc:39:25: error: reference to 'size' is ambiguous
   39 |         for (int j=0 ;j<size ;j++)
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:12:5: note:                 'int size'
   12 | int size ;
      |     ^~~~