Language: C++

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;

struct itm { int w;  int val; };
bool operator<(itm &lhs, itm &rhs) { return lhs.w < rhs.w; };
bool operator>(itm &lhs, itm &rhs) { return lhs.val > rhs.val; };

int main() {

	cin.tie(0);

	int N, W;
	cin >> N >> W;

	vector<itm> item(N);
	FOR(i, 0, N) cin >> item[i].w >> item[i].val;
	int w0 = item[0].w;
	sort(item.begin(), item.end());

	vector<vector<itm>> numw(4);
	for (const auto &ele : item) {
		
		FOR(i, 0, 4) if (ele.w == w0 + i) numw[i].emplace_back(ele);
	}
	itm zero;
	zero.w = 0; zero.val = 0;
	FOR(i, 0, 4) numw[i].emplace_back(zero);
	FOR(i, 0, 4) sort(numw[i].begin(), numw[i].end(),operator>);

	DMP(numw[0].size());

	lint ans = 0, tmp = 0;
	FOR(i0, 0, numw[0].size())FOR(i1, 0, numw[1].size())FOR(i2, 0, numw[2].size())FOR(i3, 0, numw[3].size()) {
		
		tmp = 0;
		DMP((i0 + i1 + i2 + i3)*w0 + i1 + 2 * i2 + 3 * i3);
		if ((i0 + i1 + i2 + i3)*w0 + i1 + 2 * i2 + 3 * i3 <= W) {
			FOR(ii0, 0, i0) tmp += numw[0][ii0].val;
			FOR(ii1, 0, i1) tmp += numw[1][ii1].val;
			FOR(ii2, 0, i2) tmp += numw[2][ii2].val;
			FOR(ii3, 0, i3) tmp += numw[3][ii3].val;
			ans = ans < tmp ? tmp : ans;
		}
	}

	cout << ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:26: error: no matching function for call to 'sort(std::vector<itm>::iterator, std::vector<itm>::iterator, <unresolved overloaded function type>)'
   50 |         FOR(i, 0, 4) sort(numw[i].begin(), numw[i].end(),operator>);
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   template argument deduction/substitution failed:
a.cc:50:26: note:   couldn't deduce template parameter '_Compare'
   50 |         FOR(i, 0, 4) sort(numw[i].begin(), numw[i].end(),operator>);
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = __gnu_cxx::__normal_iterator<itm*, std::vector<itm> >; _Tp = void]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1:   required by substitution of 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator) [with _ExecutionPolicy = __gnu_cxx::__normal_iterator<itm*, std::vector<itm> >; _RandomAccessIterator = __gnu_cxx::__normal_iterator<itm*, std::vector<itm> >]'
a.cc:50:19:   required from here
   50 |         FOR(i, 0, 4) sort(numw[i].begin(), numw[i].end(),operator>);
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, void>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~