Pagini recente » Cod sursa (job #326092) | Cod sursa (job #1424674) | Cod sursa (job #2292029) | Cod sursa (job #2785407) | Cod sursa (job #1199818)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
int n, gold;
cin >> n >> gold;
vector<int> weights(n);
vector<int> profits(n);
for (int i = 0; i < n; i++) {
cin >> weights[i] >> profits[i];
}
vector<int> totalprofits(gold+1);
for (int i = 0; i < n; i++) {
for (int j = gold; j >= 0; j--) {
if (j >= weights[i]) {
totalprofits[j] = max(totalprofits[j], totalprofits[j-weights[i]]+profits[i]);
}
}
}
printf("%d\n", totalprofits[gold]);
return 0;
}