Pagini recente » Cod sursa (job #1514597) | Cod sursa (job #299149) | Cod sursa (job #732775) | Cod sursa (job #637161) | Cod sursa (job #1571696)
#include <fstream>
using namespace std;
const int MAXG = 10005;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int profit[MAXG];
int g;
int main()
{
int n;
in >> n >> g;
for (int i = 0;i <= g;++i)
profit[i] = -1;
int valoare,greutate;
for (int obiect = 1;obiect <= n;++obiect)
{
in >> greutate >> valoare;
for (int i = g - greutate;i >= 0;--i)
if (profit[i] != -1 && profit[i + greutate] < profit[i] + valoare)
profit[i + greutate] = profit[i] + valoare;
if (valoare > profit[greutate])
profit[greutate] = valoare;
}
int rasp = -1;
for (int i = 0;i <= g;++i)
if (rasp < profit[i])
rasp = profit[i];
out << rasp << '\n';
return 0;
}