Language: C++

#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
#define pii map<int,int>
 
int n,w;
 
//添え字p,残り容量qから最大の利益となる利益vを返す
int np(vector<pii> &item, int p, int q){
    static vector<vector<int>> dp;
    for(auto a : dp){
        if(a[0]==p && a[1]==q){
            return a[2];
        }
    }
    int v;
    if(p==n){
        v=0;
    }else if(q<item[p].first){
        v=np(item,p+1,q);
    }else{
        v=max(np(item,p+1,q), np(item,p+1,q-item[p].first)+item[p].second);
    }
    dp.push_back(vector<int>{p,q,v});
    return v;
}
 
int main(void){
    cin>>n>>w;
    vector<pii> item(n,pii(0,0));
    for(int i=0;i<n;i++){
        cin>>item[i].first>>item[i].second;
    }
    cout<<np(item,0,w);
}

Compiler output:
a.cc: In function 'int np(std::vector<std::map<int, int> >&, int, int)':
a.cc:21:24: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'first'
   21 |     }else if(q<item[p].first){
      |                        ^~~~~
a.cc:24:53: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'first'
   24 |         v=max(np(item,p+1,q), np(item,p+1,q-item[p].first)+item[p].second);
      |                                                     ^~~~~
a.cc:24:68: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'second'
   24 |         v=max(np(item,p+1,q), np(item,p+1,q-item[p].first)+item[p].second);
      |                                                                    ^~~~~~
a.cc: In function 'int main()':
a.cc:34:22: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'first'
   34 |         cin>>item[i].first>>item[i].second;
      |                      ^~~~~
a.cc:34:37: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'second'
   34 |         cin>>item[i].first>>item[i].second;
      |                                     ^~~~~~
In file included from /usr/include/c++/14/map:63,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]':
a.cc:32:31:   required from here
   32 |     vector<pii> item(n,pii(0,0));
      |                               ^
/usr/include/c++/14/bits/stl_map.h:287:38: error: no matching function for call to 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::_M_insert_range_unique(int&, int&)'
  287 |         { _M_t._M_insert_range_unique(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_tree.h:1096:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, int>; _KeyOfValue = std::_Select1st<std::pair<const int, int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
 1096 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1096:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)std::is_same<std::pair<const int, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = int]':
/usr/include/c++/14/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  287 |         { _M_t._M_insert_range_unique(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:32:31:   required from here
   32 |     vector<pii> item(n,pii(0,0));
      |                               ^
/usr/include/c++/14/bits/stl_tree.h:1095:58: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1095 |         __enable_if_t<__same_value_type<_InputIterator>::value>
      |                                                          ^~~~~
/usr/include/c++/14/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]':
a.cc:32:31:   required from here
   32 |     vector<pii> item(n,pii(0,0));
      |                               ^
/usr/include/c++/14/bits/stl_tree.h:1105:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value))> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, int>; _KeyOfValue = std::_Select1st<std::pair<const int, int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
 1105 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1105:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<((bool)(! std::is_same<std::pair<const int, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value)), void> std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = int]':
/usr/include/c++/14/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  287 |         { _M_t._M_insert_range_unique(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:32:31:   required from here
   32 |     vector<pii> item(n,pii(0,0));
      |                               ^
/usr/include/c++/14/bits/stl_tree.h:1104:59: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1104 |         __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                           ^~~~~