Language: C++

#include<iostream>
#include<cmath>
#include<climits>
#include<functional>

using namespace std;
int dp[101][100005];
int main() {
   int N, W;

   cin >> N >> W;
   int w[ N ], v[ N ];
   int totalMax = 0;
   for( int i = 0; i < N; i++ ) {
      cin >> w[ i ] >> v[ i ];
      totalMax += v[ i ];
   }

 /*  int **dp = ( int ** ) malloc( sizeof( int * ) * N );
   for( int i = 0; i < N; i++ ) {
      dp[ i ] = ( int * ) malloc( sizeof( int ) * totalMax + 1 );*/
   }
   for( int i = 0; i < N; i++ ) {
      for( int j = 0; j < totalMax + 1; j++ ) {
         dp[ i ][ j ] = INT_MAX;
      }
   }

   function< int ( int, int ) > getDp;
   getDp = [ & ] ( int cn, int cv ) -> int {
      if( cv <= 0 ) {
         return 0;
      }
      if( cn == 0 ) {
         if( cv <= v[ cn ] ) {
            return w[ cn ];
         }
         return INT_MAX - 1;
      }
      if( dp[ cn ][ cv ] != INT_MAX ) {
         return dp[ cn ][ cv ];
      }
      auto path1 = getDp( cn - 1, cv - v[ cn ] );
      path1 = path1 == INT_MAX - 1 ? path1 : path1 + w[ cn ];
      dp[ cn ][ cv ] = min( path1, getDp( cn - 1, cv ) );

      return dp[ cn ][ cv ];
   };

   // Binary search with two ends
   function< int ( int, int ) > search;
   search = [ & ] ( int start, int end ) -> int {
      if( start == end ) {
         return start;
      }
      if( start + 1 == end ) {
         if( getDp( N - 1, end ) <= W ) {
            return end;
         } else {
            return start;
         }
      }
      auto mid = ( start + end ) / 2;
      auto mV = getDp( N - 1, mid );
      if( mV <= W ) {
         return search( mid, end );
      } else {
         return search( start, mid );
      }
   };

   cout << search( 0, totalMax );
   return 0;
}

Compiler output:
a.cc:23:4: error: expected unqualified-id before 'for'
   23 |    for( int i = 0; i < N; i++ ) {
      |    ^~~
a.cc:23:20: error: 'i' does not name a type
   23 |    for( int i = 0; i < N; i++ ) {
      |                    ^
a.cc:23:27: error: 'i' does not name a type
   23 |    for( int i = 0; i < N; i++ ) {
      |                           ^
a.cc:30:4: error: 'getDp' does not name a type
   30 |    getDp = [ & ] ( int cn, int cv ) -> int {
      |    ^~~~~
a.cc:52:4: error: reference to 'search' is ambiguous
   52 |    search = [ & ] ( int start, int end ) -> int {
      |    ^~~~~~
In file included 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,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidates are: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
a.cc:51:33: note:                 'std::function<int(int, int)> search'
   51 |    function< int ( int, int ) > search;
      |                                 ^~~~~~
a.cc:72:4: error: 'cout' does not name a type
   72 |    cout << search( 0, totalMax );
      |    ^~~~
a.cc:73:4: error: expected unqualified-id before 'return'
   73 |    return 0;
      |    ^~~~~~
a.cc:74:1: error: expected declaration before '}' token
   74 | }
      | ^