Language: C++

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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,W;cin>>n>>W;
  vector<int> dp(w),a[4];
  rep(i,n){
    int w,v,w1;cin>>w>>v;
    if(i==0)w1=w;
    a[w-w1].push_back(v);
  }
  rep(i,4){
    sort(a[i].begin(),a[i].end());
    a[i].push_back(0);
    reverse(a[i].begin(),a[i].end());
    for(int j=1;j<a[i].size();j++)a[i][j]+=a[i][j-1];
  }
  ll ans=0;
  for(int i=0;i<a[0].size();i++){
    for(int j=0;j<a[1].size();j++){
      for(int k=0;k<a[2].size();k++){
        for(int l=0;l<a[3].size();l++){
          int fact=i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3);
          if(fact<=W)ans=max(ans,a[0][i]+a[1][j]+a[2][k]+a[3][l]);
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:11:18: error: 'w' was not declared in this scope
   11 |   vector<int> dp(w),a[4];
      |                  ^
a.cc:28:22: error: 'w1' was not declared in this scope; did you mean 'y1'?
   28 |           int fact=i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3);
      |                      ^~
      |                      y1
a.cc:29:29: error: no matching function for call to 'max(ll&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   29 |           if(fact<=W)ans=max(ans,a[0][i]+a[1][j]+a[2][k]+a[3][l]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:29:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   29 |           if(fact<=W)ans=max(ans,a[0][i]+a[1][j]+a[2][k]+a[3][l]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:29:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   29 |           if(fact<=W)ans=max(ans,a[0][i]+a[1][j]+a[2][k]+a[3][l]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~