朴素
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int v[N],w[N],f[N][N];
int n,m;
int main(){
cin>>n>>m;
for(int i= 1;i<=n;i++) cin>>v[i]>>w[i];
for(int i = 1;i<=n;i++){
for(int j = 0;j<=m;j++){
//拿与不拿
if(j-v[i]>=0) f[i][j] = max(f[i-1][j],f[i][j-v[i]]+w[i]);
else f[i][j] = f[i-1][j];
}
}
cout<<f[n][m];
}