Language: C++

#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,w;
    cin>>n>>w;
    ll a[n]; ll b[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    ll dp[100001];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=w;j>=0;j--)
            if((j+a[i])<=w&&dp[j]!=-1)
                dp[j+a[i]]=max(dp[j+a[i],dp[j]+b[i]);
    }
    ll ans=0;
    for(int i=0;i<=w;i++)
      {
          cout<<dp[i]<<" "<<i<<"\n";ans=max(ans,dp[i]);
      }
    cout<<ans;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:52: error: expected ']' before ')' token
   45 |                 dp[j+a[i]]=max(dp[j+a[i],dp[j]+b[i]);
      |                                                    ^
      |                                                    ]
a.cc:45:31: error: no matching function for call to 'max(long long int&)'
   45 |                 dp[j+a[i]]=max(dp[j+a[i],dp[j]+b[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:   candidate expects 2 arguments, 1 provided
/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, 1 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:   template argument deduction/substitution failed:
a.cc:45:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |                 dp[j+a[i]]=max(dp[j+a[i],dp[j]+b[i]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~
/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:   candidate expects 2 arguments, 1 provided