Pagini recente » Cod sursa (job #2297755) | Cod sursa (job #2178302) | Cod sursa (job #1608749) | Cod sursa (job #593414) | Cod sursa (job #2883679)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, gmax, x, pr = 0;
int p[5005],g[5005],profit[10005] = {-1};
int maxim = 0;
/*
profit[j] -> profitul maxim pe care il putem obtine cu obiecte ce au suma greutatilor j
for(int i = 1 ; i <= n; i++)
{
for(int j = gmax - g[i]; j >= 0; j++)
{
profit[j + g[i]] = max(profit[j + g[i]], profit[j] + pret[i])
}
}
*/
int main()
{
fin >> n >> gmax;
for(int i = 1; i <= n; i++)
{
fin >> g[i] >> p[i];
}
profit[0] = 0;
for(int i = 1 ; i <= n; i++)
{
for(int j = gmax - g[i]; j >= 0; j--)
{
profit[j + g[i]] = max(profit[j + g[i]], profit[j] + p[i]);
}
}
for(int i = 1; i <= gmax; i++)
{
maxim = max(profit[i],maxim);
}
fout << maxim;
return 0;
}