Language: C++

#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

int main()
{
  uint64_t N, W;
  cin >> N >> W;

  vector<VectorItem> items(N);
  N_TIMES(n, N) { cin >> items[n]; }

  array<vector<uint64_t>, 2> dp;
  N_TIMES(i, 2) { dp[i] = vector<uint64_t>(W + 1, 0); }
  N_TIMES(n, N) {
    N_TIMES(w, W + 1) {
      dp[(n + 1) % 2][w] = max(dp[(n + 1) % 2][w], dp[n % 2][w]);

      if (w + items[n].w <= W) {
        dp[(n + 1) % 2][w + items[n].w] = max(
          dp[(n + 1) % 2][w + items[n].w], 
          max(
            dp[n % 2][w + items[n].w], 
            dp[n % 2][w] + items[n].v
          )
        );
      }
    }
  }
  cout << *max_element(dp[N % 2].begin(), dp[N % 2].end()) << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   25 |   cin >> N >> W;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:27:3: error: 'vector' was not declared in this scope
   27 |   vector<VectorItem> items(N);
      |   ^~~~~~
a.cc:27:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:27:10: error: 'VectorItem' was not declared in this scope
   27 |   vector<VectorItem> items(N);
      |          ^~~~~~~~~~
a.cc:27:22: error: 'items' was not declared in this scope
   27 |   vector<VectorItem> items(N);
      |                      ^~~~~
a.cc:30:3: error: 'array' was not declared in this scope; did you mean 'std::array'?
   30 |   array<vector<uint64_t>, 2> dp;
      |   ^~~~~
      |   std::array
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: 'std::array' declared here
   99 |     struct array;
      |            ^~~~~
a.cc:30:24: error: expected primary-expression before '>' token
   30 |   array<vector<uint64_t>, 2> dp;
      |                        ^
a.cc:30:25: error: expected primary-expression before ',' token
   30 |   array<vector<uint64_t>, 2> dp;
      |                         ^
a.cc:30:30: error: 'dp' was not declared in this scope
   30 |   array<vector<uint64_t>, 2> dp;
      |                              ^~
a.cc:31:42: error: expected primary-expression before '>' token
   31 |   N_TIMES(i, 2) { dp[i] = vector<uint64_t>(W + 1, 0); }
      |                                          ^
a.cc:34:28: error: 'max' was not declared in this scope; did you mean 'std::max'?
   34 |       dp[(n + 1) % 2][w] = max(dp[(n + 1) % 2][w], dp[n % 2][w]);
      |                            ^~~
      |                            std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:47:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   47 |   cout << *max_element(dp[N % 2].begin(), dp[N % 2].end()) << endl;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:47:12: error: 'max_element' was not declared in this scope; did you mean 'std::max_element'?
   47 |   cout << *max_element(dp[N % 2].begin(), dp[N % 2].end()) << endl;
      |            ^~~~~~~~~~~
      |            std::max_element
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note: 'std::max_element' declared here
  528 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~
a.cc:47:63: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   47 |   cout << *max_element(dp[N % 2].begin(), dp[N % 2].end()) << endl;
      |                                                               ^~~~
      |                                                               std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~