Language: C++

#include <bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};
 
const int N = 1e5+1;
int dp[105][N];
int wt[105],val[105];
 
int helper(int i,int W)
{
	if(i<0)
	return 0;
	if(dp[i][W]!=-1)
	return dp[i][W];
	int ans=helper(i-1,W);
	if(wt[i]<=W)
	ans=max(ans,val[i]+helper(i-1,W-wt[i]));
	return dp[i][W]=ans;
}
 
void solve()
{
	int i,n,W;
	cin>>n>>W;
	for(i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	mem(dp,-1);
	cout<<helper(n-1,W)<<endl;
}
 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};

const int N = 1e9+1;
int dp[105][N];
int wt[105],val[105];

int helper(int i,int W)
{
	if(i<0)
	return 0;
	if(dp[i][W]!=-1)
	return dp[i][W];
	int ans=helper(i-1,W);
	if(wt[i]<=W)
	ans=max(ans,val[i]+helper(i-1,W-wt[i]));
	return dp[i][W]=ans;
}

void solve()
{
	int i,n,W;
	cin>>n>>W;
	for(i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	mem(dp,-1);
	cout<<helper(n-1,W)<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}

Compiler output:
a.cc:86:11: error: redefinition of 'const long long int INF'
   86 | const int INF = 1e9;
      |           ^~~
a.cc:21:11: note: 'const long long int INF' previously defined here
   21 | const int INF = 1e9;
      |           ^~~
a.cc:87:11: error: redefinition of 'const long long int MOD'
   87 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:22:11: note: 'const long long int MOD' previously defined here
   22 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:88:14: error: redefinition of 'const double pi'
   88 | const double pi = acos(-1);
      |              ^~
a.cc:23:14: note: 'const double pi' previously defined here
   23 | const double pi = acos(-1);
      |              ^~
a.cc:89:5: error: redefinition of 'long long int power(long long int, long long int, long long int)'
   89 | int power(int a,int b,int m=MOD)
      |     ^~~~~
a.cc:24:5: note: 'long long int power(long long int, long long int, long long int)' previously defined here
   24 | int power(int a,int b,int m=MOD)
      |     ^~~~~
a.cc:92:5: error: redefinition of 'long long int dir []'
   92 | int dir[]={-1, 0, 1, 0, -1};
      |     ^~~
a.cc:27:5: note: 'long long int dir [5]' previously defined here
   27 | int dir[]={-1, 0, 1, 0, -1};
      |     ^~~
a.cc:93:5: error: redefinition of 'long long int dx []'
   93 | int dx[]={1,1,0,-1,-1,-1, 0, 1};
      |     ^~
a.cc:28:5: note: 'long long int dx [8]' previously defined here
   28 | int dx[]={1,1,0,-1,-1,-1, 0, 1};
      |     ^~
a.cc:94:5: error: redefinition of 'long long int dy []'
   94 | int dy[]={0,1,1, 1, 0,-1,-1,-1};
      |     ^~
a.cc:29:5: note: 'long long int dy [8]' previously defined here
   29 | int dy[]={0,1,1, 1, 0,-1,-1,-1};
      |     ^~
a.cc:96:11: error: redefinition of 'const long long int N'
   96 | const int N = 1e9+1;
      |           ^
a.cc:31:11: note: 'const long long int N' previously defined here
   31 | const int N = 1e5+1;
      |           ^
a.cc:97:5: error: redefinition of 'long long int dp [105][100001]'
   97 | int dp[105][N];
      |     ^~
a.cc:32:5: note: 'long long int dp [105][100001]' previously declared here
   32 | int dp[105][N];
      |     ^~
a.cc:98:5: error: redefinition of 'long long int wt [105]'
   98 | int wt[105],val[105];
      |     ^~
a.cc:33:5: note: 'long long int wt [105]' previously declared here
   33 | int wt[105],val[105];
      |     ^~
a.cc:98:13: error: redefinition of 'long long int val [105]'
   98 | int wt[105],val[105];
      |             ^~~
a.cc:33:13: note: 'long long int val [105]' previously declared here
   33 | int wt[105],val[105];
      |             ^~~
a.cc:100:5: error: redefinition of 'long long int helper(long long int, long long int)'
  100 | int helper(int i,int W)
      |     ^~~~~~
a.cc:35:5: note: 'long long int helper(long long int, long long int)' previously defined here
   35 | int helper(int i,int W)
      |     ^~~~~~
a.cc:112:6: error: redefinition of 'void solve()'
  112 | void solve()
      |      ^~~~~
a.cc:47:6: note: 'void solve()' previously defined here
   47 | void solve()
      |      ^~~~~
a.cc:122:9: error: redefinition of 'int32_t main()'
  122 | int32_t main()
      |         ^~~~
a.cc:57:9: note: 'int32_t main()' previously defined here
   57 | int32_t main()
      |         ^~~~