Pagini recente » Cod sursa (job #44357) | Cod sursa (job #2871322) | Cod sursa (job #2647635) | Cod sursa (job #126229) | Cod sursa (job #1560999)
# include <cstdio>
# include <algorithm>
# define G 10010
using namespace std;
int numar_obiecte, greutate_maxima, greutate, profit;
int sol[G];
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
scanf("%d %d\n", &numar_obiecte, &greutate_maxima);
for(int i=1; i<=numar_obiecte; ++i)
{
scanf("%d %d\n", &greutate, &profit);
for(int j=greutate_maxima; j>=greutate; --j)
sol[j]=max(sol[j],sol[j-greutate]+profit);
}
printf("%d\n", sol[greutate_maxima]);
}