Pagini recente » Cod sursa (job #2757734) | Cod sursa (job #238594) | Cod sursa (job #2517051) | Cod sursa (job #1801423) | Cod sursa (job #2602252)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,g,w,p,v[5001],profit[5001],d[10001],max1;
int main()
{
fin>>n>>g;
for(int i=1;i<=n;i++)
{
fin>>v[i]>>profit[i];
}
for(int x=1;x<=n;x++)
{
for(int i=g-v[x];i>= 0; --i)
if(d[i] + profit[x] > d[i + v[x]])
d[i + v[x]] = d[i] + profit[x];
}
for(int i=1;i<=g;i++)
if(d[i]>max1)
max1=d[i];
fout<<max1;
}