Pagini recente » Cod sursa (job #1681198) | Cod sursa (job #2310860) | Cod sursa (job #2439956) | Cod sursa (job #1810409) | Cod sursa (job #3128080)
#include <fstream>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
const int MAX_WEIGHT = 1e5;
int MaxValue[MAX_WEIGHT];
int N, Max_Weight, Answer;
int main()
{
cin >> N >> Max_Weight;
while(N--)
{
int Weight, Value;
cin >> Weight >> Value;
for(int Curent_Weight = Max_Weight; Curent_Weight >= Weight; Curent_Weight--)
{
MaxValue[Curent_Weight] = max(MaxValue[Curent_Weight], MaxValue[Curent_Weight - Weight] + Value);
Answer = max(Answer, MaxValue[Curent_Weight]);
}
}
cout << Answer;
return 0;
}