Pagini recente » Cod sursa (job #551057) | Cod sursa (job #1444683) | Cod sursa (job #1517899) | Cod sursa (job #2818048) | Cod sursa (job #3290040)
#include <fstream>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int profitmax[10005];
int main()
{
int n, gmax, rez;
cin>>n>>gmax;
for(int i = 1; i <= n; ++i)
{
int greutate, profit;
cin>>greutate>>profit;
for(int g = gmax; g >= greutate; --g)
{
profitmax[g] = max(profitmax[g], profitmax[g-greutate] + profit);
rez = max(rez, profitmax[g]);
}
}
cout<<rez;
return 0;
}