Pagini recente » Profil Robert Hangu | Cod sursa (job #2790820) | Cod sursa (job #1789130) | Cod sursa (job #946897) | Cod sursa (job #1462611)
#include <cstdio>
using namespace std;
int d[10001];
int main()
{
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
int n,i,G,g,p,smax,max,j;
scanf("%d%d",&n,&G);
smax=0;
for(i=1;i<=G;i++) d[i]=-1;
for(i=1;i<=n;i++)
{
scanf("%d%d",&g,&p);
for(j=smax;j>=0;j--)
{
if(d[j]!=-1 && j+g<=G)
if(d[j+g]<d[j]+p)
d[j+g]=d[j]+p;
if(j+g>smax) smax=j+g;
}
}
max=0;
for(i=G;i>=1;i--)
if(d[i]>max) max=d[i];
printf("%d\n",max);
return 0;
}