Language: C++

#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef pair<ll, ll>P;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

ll par[100000], depth[100000];
static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}
#define yo 100001
//------------------変数-----------------------//
ll d, n, t[300] = {}, dp[101][101][301][101] = {}, W;
P p[101] = {};
vector<ll> zero, one, two, three;
ll mini;
//-------------------関数----------------------//

ll DP(ll num, ll onenum, ll weight,ll tw) {
	if (num*mini + weight > W) { return -INF; }
	if (num == n) { return 0; }
	if (dp[num][onenum][weight][tw]>=0) { return dp[num][onenum][weight][tw]; }
	ll cnt = 0; 
	for (ll izryt = 0; izryt < 4; izryt++)
	{
	//	cout << izryt << endl;
		if (izryt == 0) {
			if (zero.size()) {
				ll hoge = zero.back(); zero.pop_back();
				ll bwam = DP(num + 1, onenum , weight,tw) + hoge; cnt = max(cnt, bwam); 
				zero.push_back(hoge);
			}
		}
		if (izryt == 1) {
			if (one.size()) {
				ll hoge = one.back(); one.pop_back();
				ll bwam = DP(num + 1, onenum+1, weight + 1,tw) + hoge; cnt = max(cnt, bwam); 
				one.push_back(hoge);
			}
		}
		if (izryt == 2) {
			if (two.size()) {
				ll hoge = two.back(); two.pop_back();
				ll bwam = DP(num + 1, onenum, weight + 2,tw+1) + hoge;  cnt = max(cnt, bwam); 
				two.push_back(hoge);
			}
		}
		if (izryt == 3) {
			if (three.size()) {
				ll hoge = three.back(); three.pop_back();
				ll bwam = DP(num + 1, onenum, weight + 3,tw) + hoge; cnt = max(cnt, bwam); 
				three.push_back(hoge);
			}
		}
	}

		return dp[num][onenum][weight][tw] = cnt;
}

int main() {
	cin >> n >> W;
	fill_all(dp, (ll)-1);
	REP(i, n) {
		ll w, v; cin >> w >> v;
		p[i].first = w; p[i].second = v;
	}
	sort(p, p + n);
	mini = p[0].first;
	REP(i, n) {
		ll izryt = p[i].first - mini;
		if (izryt == 0) { zero.push_back(p[i].second); }
		if (izryt == 1) { one.push_back(p[i].second); }
		if (izryt == 2) { two.push_back(p[i].second); }
		if (izryt == 3) { three.push_back(p[i].second); }
	}
	cout << DP(0, 0, 0, 0) << endl;
	return 0;
}





Compiler output:
a.cc: In function 'void calc_comb()':
a.cc:37:14: error: 'uint32_t' was not declared in this scope
   37 |         for (uint32_t i = 0; i <= MAX_NUM; i++) {
      |              ^~~~~~~~
a.cc:12:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   11 | #include<cstring>
  +++ |+#include <cstdint>
   12 | #include<vector>
a.cc:37:30: error: 'i' was not declared in this scope
   37 |         for (uint32_t i = 0; i <= MAX_NUM; i++) {
      |                              ^
a.cc:38:30: error: expected ';' before 'j'
   38 |                 for (uint32_t j = 0; j <= i; j++) {
      |                              ^~
      |                              ;
a.cc:38:38: error: 'j' was not declared in this scope; did you mean 'jn'?
   38 |                 for (uint32_t j = 0; j <= i; j++) {
      |                                      ^
      |                                      jn