#include<iostream>
#include<cstring>
using namespace std;
int n;
int Max = 0;
//记录重量
int res = 0;
//记录不可超重
int Mweight;
int value[100];
int weight[100];
int history[100];
void Backtrack(int t){
if(t>n){
//记录价格
int coins = 0;
for(int i = 1;i<=n;i++){
coins+=value[i]*history[i];
}
Max = Max>coins?Max:coins;
return;
}
res += weight[t];
history[t] = 1;
if(res<=Mweight)Backtrack(t+1);
res -= weight[t];
history[t] = 0;
Backtrack(t+1);
}
using namespace std;
int main(){
cin>>n;
cin>>Mweight;
for(int i = 1;i<=n;i++){
cin>>value[i]>>weight[i];
}
memset(history,0,sizeof history);
Backtrack(1);
cout<<Max<<endl;
return 0;
}
value是商品价格
history是商品是否加入
weight是商品重量
Max是满足不超过Mweight情况下的最大价值取值