Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

typedef std::unique_ptr<long long[]> smart_array;

long long knapsack(std::pair<long long, long long>* pairs, smart_array* temp, int n, int w, int index = 0) {
	if (index >= n || w <= 0)
		return 0;

	if (temp[index][w] == 0) {
		long long tmp = 0;
		if (pairs[index].first <= w)
		tmp = pairs[index].second + knapsack(pairs, temp, n, w - pairs[index].first, index + 1);

		long long tmp2 = knapsack(pairs, temp, n, w, index + 1);
		
		temp[index][w] = std::max(tmp, tmp2);
	}
	return temp[index][w];
}

int main() {
	using std::cin; using std::cout; using std::endl;
	int n = 0, w = 0; cin >> n >> w;
	std::pair<long long, long long>* pairs = new std::pair<long long, long long>[n] {};

	for (size_t i = 0; i < n; i++)
		cin >> pairs[i].first >> pairs[i].second;

	auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
	for (size_t i = 0; i <= n; i++)
		tempArr[i] = smart_array(new long long[__int64(w) + 1]{});

	cout << knapsack(pairs, tempArr.get(), n, w) << endl;

	delete[] pairs;

	return 0;
}

Compiler output:
a.cc:5:14: error: 'unique_ptr' in namespace 'std' does not name a template type
    5 | typedef std::unique_ptr<long long[]> smart_array;
      |              ^~~~~~~~~~
a.cc:4:1: note: 'std::unique_ptr' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
    3 | #include <algorithm>
  +++ |+#include <memory>
    4 | 
a.cc:7:60: error: 'smart_array' has not been declared
    7 | long long knapsack(std::pair<long long, long long>* pairs, smart_array* temp, int n, int w, int index = 0) {
      |                                                            ^~~~~~~~~~~
a.cc: In function 'long long int knapsack(std::pair<long long int, long long int>*, int*, int, int, int)':
a.cc:11:24: error: invalid types 'int[int]' for array subscript
   11 |         if (temp[index][w] == 0) {
      |                        ^
a.cc:18:28: error: invalid types 'int[int]' for array subscript
   18 |                 temp[index][w] = std::max(tmp, tmp2);
      |                            ^
a.cc:20:27: error: invalid types 'int[int]' for array subscript
   20 |         return temp[index][w];
      |                           ^
a.cc: In function 'int main()':
a.cc:31:29: error: 'unique_ptr' is not a member of 'std'
   31 |         auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
      |                             ^~~~~~~~~~
a.cc:31:29: note: 'std::unique_ptr' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
a.cc:31:40: error: 'smart_array' was not declared in this scope
   31 |         auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
      |                                        ^~~~~~~~~~~
a.cc:31:52: error: expected primary-expression before ']' token
   31 |         auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
      |                                                    ^
a.cc:31:59: error: 'smart_array' does not name a type
   31 |         auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
      |                                                           ^~~~~~~~~~~
a.cc:31:70: error: expected ')' before '[' token
   31 |         auto tempArr = std::unique_ptr<smart_array[]>(new smart_array[n + 1]{});
      |                                                      ~               ^
      |                                                                      )
a.cc:33:56: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
   33 |                 tempArr[i] = smart_array(new long long[__int64(w) + 1]{});
      |                                                        ^~~~~~~
      |                                                        __int64_t