Language: C++

#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
//#define ll long long
#define P pair<ll,ll>

ll k;
int n,m;
int v[1000],w[1000];
vector<int> t[5];


int main(){
	cin>>n>>m;;
	rep(i,5)t[i].resize(0);

	int k;
	rep(i,n){
		cin>>w[i]>>v[i];
		k=w[0];
		t[k+3-w[i]].push_back(v[i]);
	}

	for(int i=0;i<=3;i++){
		//cout<<t[i].size()<<endl;
		sort(t[i].begin(),t[i].end(),greater<int>());
	}
	
	ll ans=0;
	rep(i,max(1,(int)t[0].size()+1)){
		rep(j,max(1,(int)t[1].size()+1)){
			rep(x,max(1,(int)t[2].size()+1)){
				rep(y,max(1,(int)t[3].size()+1)){
					ll tmp=0,we=0;
						rep(z,i)tmp+=t[0][z],we+=k+3;
						rep(z,j)tmp+=t[1][z],we+=k+2;
						rep(z,x)tmp+=t[2][z],we+=k+1;
						rep(z,y)tmp+=t[3][z],we+=k;
						//cout<<i<<" "<<j<<" "<<x<<" "<<y<<" "<<" "<<we<<" "<<tmp<<endl;
						if(we<=m)ans=max(ans,tmp);
				}
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc:15:12: error: '__int64' does not name a type; did you mean '__int64_t'?
   15 | #define ll __int64
      |            ^~~~~~~
a.cc:19:1: note: in expansion of macro 'll'
   19 | ll k;
      | ^~
a.cc: In function 'int main()':
a.cc:15:12: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
   15 | #define ll __int64
      |            ^~~~~~~
a.cc:41:9: note: in expansion of macro 'll'
   41 |         ll ans=0;
      |         ^~
a.cc:46:44: error: expected ';' before 'tmp'
   46 |                                         ll tmp=0,we=0;
      |                                            ^~~
a.cc:47:57: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   47 |                                                 rep(z,i)tmp+=t[0][z],we+=k+3;
      |                                                         ^~~
      |                                                         tm
a.cc:47:70: error: 'we' was not declared in this scope; did you mean 'w'?
   47 |                                                 rep(z,i)tmp+=t[0][z],we+=k+3;
      |                                                                      ^~
      |                                                                      w
a.cc:48:57: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   48 |                                                 rep(z,j)tmp+=t[1][z],we+=k+2;
      |                                                         ^~~
      |                                                         tm
a.cc:48:70: error: 'we' was not declared in this scope; did you mean 'w'?
   48 |                                                 rep(z,j)tmp+=t[1][z],we+=k+2;
      |                                                                      ^~
      |                                                                      w
a.cc:49:57: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   49 |                                                 rep(z,x)tmp+=t[2][z],we+=k+1;
      |                                                         ^~~
      |                                                         tm
a.cc:49:70: error: 'we' was not declared in this scope; did you mean 'w'?
   49 |                                                 rep(z,x)tmp+=t[2][z],we+=k+1;
      |                                                                      ^~
      |                                                                      w
a.cc:50:57: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   50 |                                                 rep(z,y)tmp+=t[3][z],we+=k;
      |                                                         ^~~
      |                                                         tm
a.cc:50:70: error: 'we' was not declared in this scope; did you mean 'w'?
   50 |                                                 rep(z,y)tmp+=t[3][z],we+=k;
      |                                                                      ^~
      |                                                                      w
a.cc:52:52: error: 'we' was not declared in this scope; did you mean 'w'?
   52 |                                                 if(we<=m)ans=max(ans,tmp);
      |                                                    ^~
      |                                                    w
a.cc:52:58: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |                                                 if(we<=m)ans=max(ans,tmp);
      |                                                          ^~~
      |                                                          abs
a.cc:52:70: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   52 |                                                 if(we<=m)ans=max(ans,tmp);
      |                                                                      ^~~
      |                                                                      tm
a.cc:58:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   58 |         cout<<ans<<endl;
      |               ^~~
      |               abs