Language: C++

#include <bits/stdc++.h>
#include <utility>
using namespace std;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
#define rfor(i, a, b) for(int i = a - 1; i >= b; i--)

ll n,W,dp[2][1000100],wt[110],val[110];

ll knapSack(ll V,ll n) { 
    fore(i,0,n+1) { 
        fore(v,0,V+1) {
            if (v==0)
                dp[i%2][v] = 0; 
            else if (i==0) 
                dp[i%2][v] = 100000000000; 
            else if (val[i-1] <= v) 
                dp[i%2][v] = min(wt[i-1] + dp[(i-1)%2][v-val[i-1]],dp[(i-1)%2][v]);
            else
                    dp[i%2][v] = dp[(i-1)%2][v]; 
        } 
    } 
    ll ma = 0;
    fore(i,0,V+1)if(dp[1][i] != 100000000000 && dp[1][i] <=W)ma = i;
    fore(i,0,V+1)if(dp[0][i] != 100000000000 && dp[0][i] <=W)ma = max(ma,i);
    return ma; 
} 

int main(){
    ll ma = 0;
    cin>>n>>W;
    fore(i,0,n){
        cin>>wt[i]>>val[i];
        ma = max(ma,val[i]);
    }

    cout<<knapSack(ma*n,n)<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'long long int knapSack(long long int, long long int)':
a.cc:28:70: error: no matching function for call to 'max(long long int&, int&)'
   28 |     fore(i,0,V+1)if(dp[0][i] != 100000000000 && dp[0][i] <=W)ma = max(ma,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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:28:70: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   28 |     fore(i,0,V+1)if(dp[0][i] != 100000000000 && dp[0][i] <=W)ma = max(ma,i);
      |                                                                   ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:28:70: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   28 |     fore(i,0,V+1)if(dp[0][i] != 100000000000 && dp[0][i] <=W)ma = max(ma,i);
      |                                                                   ~~~^~~~~~