Pagini recente » Cod sursa (job #793509) | Cod sursa (job #2179566) | Cod sursa (job #2277986) | Cod sursa (job #2109934) | Cod sursa (job #1743315)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("rucsac.in");
ofstream t ("rucsac.out");
int main()
{
int n,g,weight,profit,max=-1;
f>>n>>g;
int v[10005];
for (int i=0; i<n; ++i)
{
f>>weight>>profit;
for (int j=g-weight; j; --j)
if(v[j]>0)
{
if(v[j]+profit>v[j+weight]) v[j+weight]=v[j]+profit;
if(v[j+weight]>max) max=v[j+weight];
}
if(profit>v[weight]) v[weight]=profit;
if(v[weight]>max) max=v[weight];
}
t<<max;
return 0;
}