Pagini recente » Cod sursa (job #2929018) | Cod sursa (job #1688257) | Cod sursa (job #3272415) | Cod sursa (job #1949304) | Cod sursa (job #2378131)
#include <fstream>
#define GMAX 10005
#define NMAX 5005
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int g[NMAX], c[NMAX], cmax[GMAX];
int n, greut;
int main()
{
int i, j, costmax = 0;
fin >> n >> greut;
for (i = 1; i <= n; i ++)
fin >> g[i] >> c[i];
for (i = 1; i <= n; i ++)
{
for (j = greut - g[i]; j >= 0; j --)
cmax[j + g[i]] = max(cmax[j + g[i]], cmax[j] + c[i]);
//cmax[g[i]] = max(cmax[g[i]], c[i]);
}
for (i = 1; i <= greut; i ++)
costmax = max(costmax, cmax[i]);
fout << costmax << '\n';
return 0;
}