Pagini recente » Cod sursa (job #2921593) | Cod sursa (job #1470615) | Cod sursa (job #2516489) | Cod sursa (job #413923) | Cod sursa (job #2886849)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.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
{1}
{1}
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])
}
}
{1}
*/
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;
}