Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long LL;

const int N=101;
LL W[N],V[N];

int main() {
    LL n,w;
    scanf("%lld %lld", &n, &w);
    REP(i,n) scanf("%lld %lld", W+i, V+i);
    vector<LL> ws;
    map<int,vector<LL>> mp;
    REP(i,n) {
        ws.push_back(W[i]);
        mp[W[i]].push_back(V[i]);
    }
    sort(ws.begin(),ws.end());
    ws.erase(unique(ws.begin(),ws.end()),ws.end());
    for ( int i:ws ) {
        sort(mp[i].rbegin(),mp[i].rend());
        for ( int j=1; j<mp[i].size(); j++ ) {
            mp[i][j]+=mp[i][j-1];
        }
    }
    if ( ws.size()==1 ) {
        int k=w/ws[0];
        k=min(n,k);
        if ( k==0 ) cout << 0 << '\n';
        else cout << mp[ws[0]][k-1] << '\n';
    }
    if ( ws.size()==2 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                if ( ws[0]*i+ws[1]*j>w ) continue;
                LL res=0;
                if ( i>0 ) res+=mp[ws[0]][i-1];
                if ( j>0 ) res+=mp[ws[1]][j-1];
                ans=max(ans,res);
            }
        }
        cout << ans << '\n';
    }
    if ( ws.size()==3 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                for ( int k=0; k<=mp[ws[2]].size(); k++ ) {
                    if ( ws[0]*i+ws[1]*j+ws[2]*k>w ) continue;
                    LL res=0;
                    if ( i>0 ) res+=mp[ws[0]][i-1];
                    if ( j>0 ) res+=mp[ws[1]][j-1];
                    if ( k>0 ) res+=mp[ws[2]][k-1];
                    ans=max(ans,res);
                }
            }
        }
        cout << ans << '\n';
    }
    if ( ws.size()==4 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                for ( int k=0; k<=mp[ws[2]].size(); k++ ) {
                    int l=w-ws[0]*i-ws[1]*j-ws[2]*k;
                    l/=ws[3];
                    if ( l<0||l>mp[ws[3]].size() ) continue;
                    LL res=0;
                    if ( i>0 ) res+=mp[ws[0]][i-1];
                    if ( j>0 ) res+=mp[ws[1]][j-1];
                    if ( k>0 ) res+=mp[ws[2]][k-1];
                    if ( l>0 ) res+=mp[ws[3]][l-1];
                    ans=max(ans,res);
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:29:14: error: no matching function for call to 'min(LL&, int&)'
   29 |         k=min(n,k);
      |           ~~~^~~~~
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:29:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   29 |         k=min(n,k);
      |           ~~~^~~~~
/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:29:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   29 |         k=min(n,k);
      |           ~~~^~~~~