0-1背包
/*
*背包状态转移方程:
*if(weight[i]>j) dp[i][j]=dp[i-1][j];
*else dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
*/
#include <iostream>
using namespace std;
const int N = 1000;
const int M = 10000;
int w[N],v[N],dp[M];
int max(int a,int b){
return a>b?a:b;
}
int main(){
int n,m,i,j;
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>w[i]>>v[i];
for(j=m;j>=w[i];j--){
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
cout<<dp[m]<<endl;
return 0;
}