Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// N個(価値v, 重さw), 重さの総和W以下, O(n \sigma v_i)
ll knapsack2(int N, int W, vector<int> v, vector<int> w){
    ll INF = 10000000000000;
    ll V_MAX = 0; // 価値の総和の最大値V_MAX
    for (int x : v) {
        V_MAX += x;
    }

    // i+1番目以降で価値j以上の時の重さの最小値がdp[i][j]
    vector<vector<ll>> dp(N+1, vector<ll>(V_MAX + 1, INF));
    for (int i = N-1; i >= 0; --i) {
        dp[i][0] = 0;
        for (int j = 1; j <= V_MAX; ++j){
            if(j <= v[i]){
                // DP[][j-v[i]]が0になるので
                dp[i][j] = min(dp[i+1][j], w[i]);
            }else{
                dp[i][j] = min(dp[i+1][j], dp[i+1][j - v[i]] + w[i]);
            }
        }
    }

    // 価値で線形探索(二分探索もできるが必要ない)
    int res = 0;
    for (int i = 0; i <= V_MAX; ++i) {
        if(DP[0][i] <= W) res = i;
    }
    return res;
}

int main() {
    // 入力
    int N, W;
    cin >> N >> W;
    vector<ll>w(N);
    vector<ll>v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    ll ans = knapsack2(N, W, v, w);
    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'll knapsack2(int, int, std::vector<int>, std::vector<int>)':
a.cc:20:31: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   20 |                 dp[i][j] = min(dp[i+1][j], w[i]);
      |                            ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:20:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   20 |                 dp[i][j] = min(dp[i+1][j], w[i]);
      |                            ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:20:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   20 |                 dp[i][j] = min(dp[i+1][j], w[i]);
      |                            ~~~^~~~~~~~~~~~~~~~~~
a.cc:30:12: error: 'DP' was not declared in this scope; did you mean 'dp'?
   30 |         if(DP[0][i] <= W) res = i;
      |            ^~
      |            dp
a.cc: In function 'int main()':
a.cc:45:30: error: could not convert 'v' from 'vector<long long int>' to 'vector<int>'
   45 |     ll ans = knapsack2(N, W, v, w);
      |                              ^
      |                              |
      |                              vector<long long int>