`
include <stdio.h
define N 1010
int max(int x,int y)
{
int z;
if(x>y) z=x;
else z=y;
return(z);
}
int main()
{
int f[N][N];
int n,m,i,j;
int v[N],w[N];
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d %d",&v[i],&w[i]);
}
for(i=1;i<=n;i++)
{
for(j=0;j<=m;j++)
{
f[i][j]=f[i-1][j];
if(j>=v[i])
{
f[i][j] = max(f[i][j],f[i-1][j-v[i]]+w[i]);
}
}
}
printf("%d",f[n][m]);
return 0;
}
`