Pagini recente » Cod sursa (job #1278066) | Cod sursa (job #369058) | Profil sweetgirl | Cod sursa (job #2092304) | Cod sursa (job #1284019)
#include <iostream>
#include <cstdio>
using namespace std;
int G,n;
int v[5001];
struct obiect{
int p,w;
}obj[5001];
int main()
{
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
scanf("%d%d",&n,&G);
for(int i=1; i<=n; i++)
scanf("%d%d",&obj[i].w,&obj[i].p);
for(int i=1; i<=n; i++)
for(int g=G; g>=0; g--)
if(obj[i].w<=g)
{
v[g]=max(obj[i].p+v[g-obj[i].w],v[g]);
}
else
{
v[g]=v[g];
}
printf("%d",v[G]);
return 0;
}